PDA

View Full Version : Tree with children rendered, but not accessible...



francescoNemesi
22 Aug 2007, 2:22 AM
Hi All,

I have a tree to which I dynamically add an AsyncTreeNode (following some user action) which is populated with a TreeLoader that returns some JSON which contains nodes and children of their children (see image below of the rendered tree) so far so good. The JSON, where applicable, already contains an array called children with the attributes o the children and other children if it's the case, this work is all done server side.

The problem is that although the tree is displayed exactly as I want it after user selection, I can not access the AsyncTreeNode (clientNode in the code and the first node in the image) children using the standard methods and/or properties, in fact the childNodes length of the AsynTreeNode is set to 0.

Can anyone tell me why this is happening and how to fix it? I guess it's something to do with the rendering of the children, but usually expand() does the trick... Any help would greatly appreciated.

Thanks!

This the code that populates the node.



function addClientToTree(tree,ruolo){

var codiceCliente = combo.getValue();

var nodeLoader = new Ext.tree.TreeLoader({dataUrl : baseDomain+"/BuildTree",
baseParams : {treeType : "pFolio",
cl : codiceCliente,
rl : ruolo}
});

var clientNode = new Ext.tree.AsyncTreeNode({
id : ruolo+'_'+codiceCliente,
text : combo.getRawValue(),
loader : nodeLoader,
cls : "leaf",
leaf : false,
draggable : false,
nodeType : "CL",
ruolo : ruolo,
codCliente : codiceCliente,
allowDelete : true
});

tree.getRootNode().appendChild(clientNode);
clientNode.expand(true,true);
clientNode.on('contextmenu', showClientTreesContextMenu);

//THIS RETURNS ZERO BUT THE CHILDREN ARE ACTUALLY DISPLAYED IN TREE
console.log(clientNode.childNodes.length);

Animal
22 Aug 2007, 2:33 AM
The Ajax load is asynchronous - it won't have completed by the time the console.log line is executed.

francescoNemesi
22 Aug 2007, 4:18 AM
Thanks!

Now I've implemented an event listener on the load of the loader, but it fires before the expand completes.

The callback function of the expand method is of no use either, as the doc explicitly says that it "(does not wait for deep expand to complete)".

Is there a way to do this? i.e. execute a function after the tree has been completely rendered (expanded)? :-?

Thanks again.

Animal
22 Aug 2007, 4:42 AM
No. Because there's no way of knowing which of the many Ajax requests triggered to load the full tree is the final bit!

It sounds like you shouldn't be using Ajax loading of nodes from URLs, but create your root node from a big lump of JSON.

francescoNemesi
22 Aug 2007, 4:56 AM
uhmm... in a way that's what I am doing... I create an empty tree. The user can then select a client name from a comboBox, a node is created on the client side (the clientNode in the code) and then a request is sent to the server with the client code among the parameters (cl).

The java servlet on the server reads the data of the client and returns a JSON "string" in the response with all the required product information for that client to populate the children of the client node...

I need an async method to do this as there are around 200000 clients and the data to display can change at any time, so I need to reload an updated version of it...

As ever, thanks for your help. Really Appreciated. =D>