EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: devnull on December 24, 2014, 09:22:29 PM



Title: get all tree leaves [Solved]
Post by: devnull on December 24, 2014, 09:22:29 PM
How can I get all of the tree leafs from a tree ??

Code:
    var mods = $('#westMenu').tree('getRoots');
    $(mods).each(function(){
      function iter(mod){
        $(mod.children).each(function(){
          var men = $(this);
          if(men[0].children) iter(men[0].children);
          else cl(men);
        })
      }
      
      var mod = $(this)[0];
      iter(mod);
    
    })

This does not seem to work !


Title: Re: get all tree leaves
Post by: stworthy on December 25, 2014, 12:27:09 AM
The code below shows how to get all the leaf nodes.
Code:
var t = $('#tt');	// the tree object
var leafs = [];
$.map(t.tree('getChildren'), function(node){
if (t.tree('isLeaf', node.target)){
leafs.push(node);
}
});
console.log(leafs)


Title: Re: get all tree leaves
Post by: devnull on December 25, 2014, 12:46:54 AM
Thanks so much and happy Christmas :-)