PDA

View Full Version : TreePanel findChild



luca.santaniello
8 Jul 2010, 5:10 AM
Hi all,

I have follow problem...

My Array contains thi objects for example:

[0] categoriaTematica = "AAA"; [0] label = "xxx"
[1] categoriaTematica = "BBB"; [1] label = "yyy"
[2] categoriaTematica = "AAA"; [2] label = "zzz"

I want generate ths tree panel:

ROOT
|_AAA
|____xxx
|____zzz
|_BBB
|____yyy

categoriatematica is group, layer is leaf.



function getNodoCategoria(categoria)
{
var root = this.getRootNode();

return root.findChild('text', categoria);
}

var root = this.getRootNode();

root.removeAll(true);

/*layers is my array as example*/

for (var i=0; i<layers.length; i=i+1)
{
var l = layers[i];

var categoriaNodo = this.getNodoCategoria(l.categoriaTematica)

if (categoriaNodo == null)
{
categoriaNodo = new Ext.tree.TreeNode({checked: true});
categoriaNodo.text = l.categoriaTematica;
categoriaNodo.expanded = true;

var stratoFoglia = new Ext.tree.TreeNode();
stratoFoglia.text = l.label;

categoriaNodo.appendChild(stratoFoglia);

root.appendChild(categoriaNodo);
}
else
{
var stratoFoglia = new Ext.tree.TreeNode();
stratoFoglia.text = l.label;

categoriaNodo.appendChild(stratoFoglia);
}
}
My problem is that this.getNodoCategoria() return always "null"... Why it don't find my node?

Help me please

Condor
8 Jul 2010, 5:31 AM
Because you are creating your nodes wrong.

Use:

var root = this.getRootNode();
root.removeAll(true);
for (var i = 0; i < layers.length; i = i + 1) {
var l = layers[i];
var categoriaNodo = this.getNodoCategoria(l.categoriaTematica)
if (!categoriaNodo) {
categoriaNodo = new Ext.tree.TreeNode({
checked: true,
text: l.categoriaTematica,
expanded: true
});
root.appendChild(categoriaNodo);
}
var stratoFoglia = new Ext.tree.TreeNode({
text: l.label
});
categoriaNodo.appendChild(stratoFoglia);
}

luca.santaniello
8 Jul 2010, 5:59 AM
thanks a lot, it's perfect!