请找到树
var TreeModel = require('tree-model');
tree = new TreeModel();
rootMain = tree.parse(
{id: 1,
children: [
{
id: "11",
children: [{id: "111"}]
},
{
id: "12",
children: [{id: "121"}, {id: "122"}]
},
{
id: "13"
}]
},
{id: 2,
children: [
{
id: "21",
children: [{id: "211"}]
},
{
id: "22",
children: [{id: "221"}, {id: "222"}]
},
{
id: "23"
}
]});
指导我如何实现这一目标。我试着用步行找到方法,但没有运气。
答案 0 :(得分:0)
首先获得对您所在节点的引用,假设为122:
var node122 = rootMain.first(n => n.model.id === "122")
然后获取父母的引用并获得第一个孩子:
var firstSiblingOfNode122 = node122.parent.children[0]