View Full Version : Needing to retrieve all the nodes from a tree

14 Aug 2008, 11:57 PM
To be able to process a number of actions on to a tree with users (dissable a team, uncheck a team when another team is selected) I need to have all the node objects which contain additional attribute to make them identifialble.

To retrieve all these nodes I have written this code. (fRootNode is the rootnode of the tree I need the nodes from)

retrieveAllChildNodes:function(fRootnode,next) {
if (typeof next == "undefined") {
foundNodes = new Array();
childNodes = fRootnode.childNodes;

for (var i = 0; i < childNodes.length; i++) {

return foundNodes;

It does retrieves the first childs of the first 4 levels and all the users of the level 4 team, but the rest of the teams on level 4 and their users are not added.

I would be pleased to learn if their is a more simple way to retrieve all the nodes in to 1 single dimensional array.

15 Aug 2008, 12:07 AM
Why is that difficult?

That being said, you could use the tree cascade method:

var out = [];
if (this.attributes.foo == 'bar') //your comparison here, "this" refers to the node.

15 Aug 2008, 12:19 AM
Thanks, the cascade method did the trick.

But their are 2 things I changed.
1. Add doesn't exist on an array so I had to change that too.
2. It doesn't check for attributes because I want the actual check to be done somewhere else.

retrieveAllChildNodes:function(fRootnode,next) {
var returnNodes = [];
returnNodes[returnNodes.length] = this;

return returnNodes;
}But I found another problem. I have read about this earlier but I can't recall the solution for it.
When a tree is fully loaded but is cascaded childnodes cannot be retrieved till they are expanded.

I have already changed the treeLoader to use preloadChildren: true, but the problem is persistant. It could be something wrong with the custom loader we use but... I can't tell, the one who build it is not currently avaible. So my question is: should 'preloadChildren: true,' fix it or is their something else I should do?

15 Aug 2008, 12:21 AM
'add' should be 'push'.

I don't know what you mean about the the second point, you can add in whatever condition you need.

15 Aug 2008, 12:35 AM
Thanks, push works also. Don't mind point 2 it's just something I wanted custom for this function. But I do found something additionally to the other problem I had.

The root node is invisseble, so the first node I see if the top of the organisation. When I do a retrieve on that I only get the root node + that node.

When I expand that node (which has 3 more levels to expand plus a numerous amounds of leafs) I can get all the nodes that are actually inside the tree, but not all expanded.

Should I expand the first level and cascade it on load for it to create it's nodes?