Rank: Newbie Groups: Member
Joined: 7/7/2011 Posts: 4
|
Hi everyone.
Ive been spending the day trying and failing to do what should be a simple task, iterate through childnodes of a treeview in JS.
I know I need a recursive method, but first of all, I have problems getting a array of all childnodes of parent.
Could anyone help out here?
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, You would first call this function to get the "sub group" of a parent node: http://doc.essentialobjects.com/library/1/jsdoc.public.navigationitem.getsubgroup.aspx
Code: JavaScript
//Get the "sub group" of a tree node. "sub group" is
//basically a collection of child nodes
var subNodes = node.getSubGroup();
The returned value is a NavigationItemGroup object, you can then call the following two functions to get all nodes: http://doc.essentialobjects.com/library/1/jsdoc.public.navigationitemgroup.getitemcount.aspxhttp://doc.essentialobjects.com/library/1/jsdoc.public.navigationitemgroup.getitembyindex.aspx
Code: JavaScript
//Create an array "nodes" that contains all sub nodes
var nodes = new Array();
for (var i = 0; i < subNodes.getItemCount(); i++)
{
nodes[i] = subNodes.getItemByIndex(i);
}
Hope this helps. Thanks
|
Rank: Newbie Groups: Member
Joined: 7/7/2011 Posts: 4
|
Thank your very much :)
I've finally managed to loop through all child nodes, it was a bit of an hassle, I don't even think I looked at the subGroup function when looking through the docs multiple times.
|