PDA

View Full Version : hasChildNodes()??????



TAG
24 Jul 2009, 1:44 AM
I create 2 function, one for add the node of tree, one for remove the node of tree, the code is:


var root = new Ext.tree.TreeNode({
text : 'Project',
id : 'rootProject',
leaf :false,
expandable : true,
expanded : true
})

var addNodoModello=function(testo,id){
if(root.findChild('id',id)==null){
root.appendChild([{
text: testo,
id : id,
leaf: false
}]);
}
}

var removeNodoModello=function(id){
var app=root.findChild('id',id);
if(app.hasChildNodes()){
root.findChild('id',id).remove();
}

var tree = new Ext.tree.TreePanel({
id: 'contenitoreAlbero',
autoScroll: true,
split: true,
animate: true,
collapseFirst: false,
useArrows: true,
enableDrag: false,
root: root,
rootVisible: true
})

var contenitoreAlbero=new Ext.Panel({
id: 'pannelloContenitoreAlbero',
title: 'Project Tree',
tbar: [{
text:'UML',
handler: function(){addNodoModello('UML','idUML');}
},{
text: 'rem UML',
handler: function(){removeNodoModello('idUML');}
}],
items: [tree]
});
}


The nodes, has the option "leaf: false" because I add other nodes to those generated.
When the node hasn't child I aspect with the method : "hasChildNodes()" give me the value "false" instead his give me "true"......I don't undestand why?

Condor
24 Jul 2009, 3:17 AM
You are creating an AsyncTreeNode instead of a TreeNode. Since you didn't specify loaded:true, hasChildNodes will always return true.

You want:

root.appendChild([new Ext.tree.TreeNode({
text: testo,
id : id,
leaf: false
})]);

TAG
24 Jul 2009, 6:35 AM
Condor Thanks......I and tree don't LOVE :)