EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: forum6691 on May 09, 2014, 08:45:42 AM



Title: How to remove all the nodes of a tree
Post by: forum6691 on May 09, 2014, 08:45:42 AM
Hello
How to remove all the nodes of tree (like a clear method for example)?

There is the remove function but it's for ONE node whose you know already the 'id', but if you don't know what nodes are inside the tree, how to do ?

Thanks for your help.


Title: Re: How to remove all the nodes of a tree
Post by: stworthy on May 09, 2014, 09:20:36 AM
Removing a tree node doest not require the 'id' value. Here is the extended method to remove all the tree nodes.
Code:
$.extend($.fn.tree.methods, {
removeAll:function(jq){
return jq.each(function(){
var roots = $(this).tree('getRoots');
for(var i=roots.length-1; i>=0; i--){
$(this).tree('remove', roots[i].target);
}
})
}
})

Calling 'removeAll' method will remove all the tree nodes.
Code:
$('#tt').tree('removeAll');


Title: Re: How to remove all the nodes of a tree
Post by: forum6691 on May 09, 2014, 10:12:31 AM
Thank you very much sworthy


Title: Re: How to remove all the nodes of a tree
Post by: forum6691 on September 12, 2014, 04:17:51 AM
I try to use the code you proposed sworthy, but it removes only one par one the nodes of the tree.

See here the demo I wrote with this problem : http://jsfiddle.net/30ddrjkj/11/

Thanks for your help


Title: Re: How to remove all the nodes of a tree
Post by: stworthy on September 12, 2014, 05:12:47 AM
Please try the updated example http://jsfiddle.net/30ddrjkj/13/