如果我写:的ExtJS TreePanel中:扩大()expandChildNodes()
rootNode.expand()
我只可以访问该根节点的子节点,但不能访问此根节点的孙子节点。我必须写:
rootNode.expandChildNodes()
为了实现它。
即使树被折叠,还有其他方法可以获得孙子或其他子节点吗?除了使用node.eachChild()
函数? 我试过了:
rootChildNode.firstChild
但它不起作用。
如果我写:的ExtJS TreePanel中:扩大()expandChildNodes()
rootNode.expand()
我只可以访问该根节点的子节点,但不能访问此根节点的孙子节点。我必须写:
rootNode.expandChildNodes()
为了实现它。
即使树被折叠,还有其他方法可以获得孙子或其他子节点吗?除了使用node.eachChild()
函数? 我试过了:
rootChildNode.firstChild
但它不起作用。
ExtJS 4x在树面板组件上有expandAll()
方法。这将递归地扩展每个节点。
:
expandTo:function(level){
treePanel.collapseAll();
treePanel.getRootNode().cascadeBy(function (node) {
if (node.getDepth() < level) { node.expand(); }
if (node.getDepth() == level) { return false; }
});
}
另一种方式来获得的后代是使用node.expand(true)
,其中节点是根节点。同样,您可以采用树中的任何节点并使用相同的代码展开其所有后代节点。常用的用途是所选节点。