我有一个如下所示的对象:
Node{
name: "root",
level: 0,
children: Array[14],
parent: null,
id: 0
}
而里面Node.children
...
Node.children[
{
name: "child1",
level: 1,
children: Array[1],
parent: root,
id: 1
},
{
name: "child2",
level: 1,
children: Array[1],
parent: root,
id: 2
},
{
name: "child3",
level: 1,
children: Array[2],
parent: root,
id: 3
},
]
在 Node.children[1].children ...
Node.children[1].children[
{
name: "child1-1",
level: 2,
children: Array[0],
parent: child1,
id: 4
}
]
我需要的是遍历 Node 对象并尝试将每个“ id
”与给定的值匹配。例如...
$.each(Node, function(i, nodes){
$.each(nodes, function (i2, nodes2){
if (nodes2.id == 5){
//do something
}
})
})