I want all the childs of given node in YUI treeview. Condition is that if the child has sub-childs then I want sub-sub-child. that is all the childs of given node including subchilds.
I think recursion may be the solution for this problem.Can anyone help me out this.
My current code is
if(curNode.hasChildren()) {
for(var child = 0; child < curNode.children.length;child++) {
alert(curNode.children[child].label);
}
}
By this code, I only get the childrens of given node and not the sub-sub-child nodes.
Tested here.
A recursive solution. This can be done more elegantly using functional style programming. This one relies on underscore.js for a cross browser
.reduceimplementation. You can rely on array.reduce if you target newer browsers.Give me a few moments to test/debug this.
I forgot the jQuery option
var array = $(root).find("*").toArray()