EasyUI Forum
April 19, 2024, 10:13:11 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to get child nodes (only folders and not leaf nodes) from easy ui tree  (Read 13062 times)
Shalini
Newbie
*
Posts: 2


View Profile
« on: July 18, 2013, 09:09:18 PM »

Hi,
I need to get the child nodes from easy ui tree. And that child nodes should only include the sub  folders and not the leaf nodes. I had achieved this with the below code. But this might have performance issue due to the for loop if i have a huge tree. Hence i would like to know if there is any other way where we can get only the sub folders. Please help me resolve this.
Code:
var node = $('#tt').tree('getSelected');
var child_node = $('#tt').tree('getChildren', node.target); // This gives all the childs i.e folders and leaf nodes.
var count = 0;
for(var i=0; i< child_node.length; i++)
{
   var child = $('#tt').tree('isLeaf', child_node.target); //Boolean - true if the child_node is leaf, else false
   if(!child)
      count = count + 1; // Increment count and get the count of Folders when leaf is false
}
alert('count' + count);

Regards,
Shalini S.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: July 20, 2013, 06:53:53 AM »

A better solution is to extend a new method. The code below is the simple implementation of the 'getFolders' method.
Code:
$.extend($.fn.tree.methods,{
getFolders: function(jq, target){
var nodes = [];
var ul = $(target).length ? $(target).next() : jq;
ul.find("div.tree-node:has(span.tree-folder)").each(function(){
nodes.push(jq.tree('getNode',this));
});
return nodes;
}
});

To get the selected node's child folders, try this:
Code:
var node = $('#tt').tree('getSelected');
var folders = $('#tt').tree('getFolders', node.target);
console.log(folders);
Logged
Shalini
Newbie
*
Posts: 2


View Profile
« Reply #2 on: August 06, 2013, 02:50:38 AM »

Hi stworthy,

Thank you so much for your solution..  Smiley
It works great.

Regards,
Shalini S.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!