PDA

View Full Version : TreePanel: issue with browsing childNodes in more than 1 level (root childNodes only)



samax
2 Mar 2010, 2:52 AM
Hello,
I need to browse the nodes of a TreePanel through 3 levels, to see if a node is avalaible in level 3. Here is my code:


var buildingsGroups = treePanel.getRootNode().childNodes;
var buildings = [], measDevices = [], j = 0, k = 0;

buildingsGroupsLoop:
for (var i = 0, len = buildingsGroups.length; i < len; i++) {
console.log('one buildingGroup');
buildings = buildingsGroups[i].childNodes;
for (j = 0, len2 = buildings.length; j < len2; j++) {
console.log('one building');
measDevices = buildings[j].childNodes;
for (k = 0, len3 = measDevices.length; k < len3; k++) {
console.log('one measDevice');
var firstMeasDeviceNode = measDevices[k];
break buildingsGroupsLoop;
}
}
}
The problem is that only the root childNodes are available. when I do a console.log on a buildingGroup, I get an empty array, even if the node as effectively children.
The best proof of it is that if I replace the code by it, I see the logs "one building" and "one measdevice" several times:



var buildingsGroups = treePanel.getRootNode().childNodes;
var buildings = [], measDevices = [], j = 0, k = 0;

buildingsGroupsLoop:
for (var i = 0, len = buildingsGroups.length; i < len; i++) {
console.log('one buildingGroup');
buildings = buildingsGroups[i].attributes.children;
for (j = 0, len2 = buildings.length; j < len2; j++) {
console.log('one building');
measDevices = buildings[j].children;
for (k = 0, len3 = measDevices.length; k < len3; k++) {
console.log('one measDevice');
var firstMeasDevice = measDevices[k];
var firstMeasDeviceNode = treePanel.getNodeById(firstMeasDevice.id);

if (firstMeasDeviceNode != null) {
break buildingsGroupsLoop;
}
}
}
}
The problem is that because of the child nodes of the sub levels aren't correctly created, the treePanel.getNodeById(firstMeasDevice.id) call doesn't works correctly (the nodeHash is not correctly filled, it contains only the first level of nodes, so the buildingGroups).

Does someone has a solution ?

samax
2 Mar 2010, 8:08 AM
Oh, I precise that the data in the tree is fully loaded, in one AJAX request. All the sub levels are therefore contained into the TreePanel.

samax
4 Mar 2010, 3:10 AM
Please, I still have this problem, it's very annoying...

(it's an up)

Zdeno
4 Mar 2010, 5:39 AM
Do you have expanded tree structure? Does every node has unique identificator? I just found issue when i filtering tree, you cant have 2 nodes with same id.

Does you TreeLoader has attribute preloadChildren:true ?

samax
5 Mar 2010, 12:36 AM
Hello,
Thank you for your answer, I have tried with preloadChidren option at true in my TreePanel's TreeLoader, and the issue is the same.

And I'm pretty sure I don't have two nodes with the same id.

Does anyone have another idea ?

Thanks.

samax
5 Mar 2010, 7:28 AM
up ?

Zdeno
5 Mar 2010, 7:43 AM
Do you have any online demo or can you add attachment?

arnaudmorvan
5 Aug 2010, 2:08 AM
Hello,

I have the same problem


Does you TreeLoader has attribute preloadChildren:true ?

Yes, I've just tested this option for this problem, but the issue is the same.

Regards

Condor
5 Aug 2010, 2:47 AM
preloadChildren:true only works if you actually supply the loader with nodes that include all children.

arnaudmorvan
5 Aug 2010, 4:18 AM
this my loader:

loader: new Ext.tree.TreeLoader({
dataUrl: "./nodes.json"; ?>,
preloadChildren: true
})

this is my json autoload by the TreeLoader

[{
"text":"folder",
"iconCls":"folder",
"checked":false,
"children":[{
"text":"file",
"iconCls":"file",
"leaf":true,
"checked":false
}]
}]

and later on user action I run this :

this.getRootNode().eachChild(function(folderNode) {
folderNode.getUI().toggleCheck(true);
folderNode.eachChild(function(fileNode) {
fileNode.getUI().toggleCheck(true);
}, this);
}, this);

before any expand of folder node, it only check folder node and not file node

I suppose I
supply the loader with nodes that include all children, is'nt it ?

Condor
5 Aug 2010, 5:30 AM
toggleCheck is the problem. It will only check the node if it is rendered.

Instead you should use:

if (node.getUI().rendered) {
node.getUI().toggleCheck(true);
} else if (Ext.isBoolean(node.attributes.checked)) {
node.attributes.checked = true;
}