Welcome Guest Search | Active Topics | Sign In | Register

TreeView iterate through childnodes in JS Options
MRmP
Posted: Thursday, July 7, 2011 9:10:15 AM
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?
eo_support
Posted: Thursday, July 7, 2011 10:27:50 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,173
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.aspx
http://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
MRmP
Posted: Friday, July 8, 2011 7:27:32 AM
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.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.