请找树
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"
}
]});
- 假设我在节点 2 上,我想知道它的第一个兄弟节点,所以它应该返回我 1。
- 其次,我在节点 13 / 12 我想知道它的第一个兄弟节点,然后它应该返回 11。
- 其次,我在节点 122 上,我想知道它的第一个兄弟节点,然后它应该返回 121。
指导我如何实现这一目标。我尝试了步行并找到方法,但没有运气。