darkcode
darkcode

Reputation: 928

Fancytree JQuery - Get node children and sub children

I'm using Fancytree (https://github.com/mar10/fancytree) and I have this tree structure:

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]. There are anyway get all the children?

A method that return: [subchild1, subchild2, subchild3, subchild4] ?

Upvotes: 1

Views: 2753

Answers (1)

mar10
mar10

Reputation: 14794

You could use the visitfunction to generate a flat list:

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.)

Upvotes: 4

Related Questions