简体   繁体   English

Fancytree JQuery-获取节点子级和子级子级

[英]Fancytree JQuery - Get node children and sub children

I'm using Fancytree ( https://github.com/mar10/fancytree ) and I have this tree structure: 我正在使用Fancytree( https://github.com/mar10/fancytree ),并且我有这个树结构:

root
 |_ child1
      |_ subchild1
      |_ subchild2
            |_ subchild3
            |_ subchild4

If the the selected node is child1 I can get the first children using window.tree.activeNode.children or window.tree.activeNode.getChildren() but that only return [subchild1, subchild2] . 如果选择的节点是child1我可以使用第一部儿童window.tree.activeNode.childrenwindow.tree.activeNode.getChildren()但只返回[subchild1, subchild2] There are anyway get all the children? 反正有所有的孩子?

A method that return: [subchild1, subchild2, subchild3, subchild4] ? 返回以下方法的方法: [subchild1, subchild2, subchild3, subchild4]

You could use the visit function to generate a flat list: 您可以使用visit函数生成一个平面列表:

var activeNode = tree.getActiveNode(),
    nodes = [];

activeNode.visit(function(node) {
    nodes.push(node);  // or node.key, ...
});

(Note that there is also the node.toDict() method to generate a nested object instead.) (请注意,还有node.toDict()方法来生成嵌套对象。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM