如何使用递归函数扩展dojo树扩展

时间:2014-06-19 07:55:24

标签: dojo tree

您好我想通过编程方式扩展dojo(1.7)树....

如何使用递归函数执行第n个节点 此代码将节点扩展到第3级但我需要它应该自动打开第n个节点

function expandAll(object) {
      object = object.slice(0,1);


nodes = tree.rootNode.getChildren();

for (var i = 0; i < nodes.length; i++) {
    node = nodes[i];
    if (node.isExpandable) {            
       if (node.getTreePath()[1].id == object[1]) {

            tree._expandNode(node);
            var childs = node.getChildren();

            for ( j = 0; j < childs.length; j++) {
                child = childs[j];
                if (child.getTreePath()[2].id == object[2]) {
                    tree._expandNode(child);
                    console.log("->" + child.getTreePath()[2].name[0]);
                    if (child.isExpandable) {
                        var subchilds = child.getChildren();
                        for ( k = 0; k < subchilds.length; k++) {
                            subchild = subchilds[k];
                            console.log("-> ->" + subchild.getTreePath()[3].name[0]);
                        }
                    }
                }

            }
        }
    }
}

0 个答案:

没有答案