Search code examples
fancytree

Get the list of leaf nodes in fancy tree


I'm using https://github.com/mar10/fancytree/ in my project. How to get the list of leaf nodes of the fancy tree at the given moment.


Solution

  • You could try this pattern:

    var leafNodes = [];
    
    tree.visit(function(node){
        if ( !node.hasChildren() ) {
            leafNodes.push(node);
        }
    });