index
方法返回指定 NavNode
在其父节点的子节点中的索引位置。
navNode.index()
该方法不接受任何参数。
返回类型为 number
的索引值,表示该节点在其父节点的子节点列表中的位置。如果节点没有父节点,则返回 -1
。
let parent = new NavNode('parent');
let child1 = new NavNode('child1');
let child2 = new NavNode('child2');
parent.addChild(child1);
parent.addChild(child2);
console.log(child1.index()); // 0
console.log(child2.index()); // 1
console.log(parent.index()); // -1
-1
。0
开始计数。NavNode.move()
方法。