PDA

View Full Version : Help:how to append node to tree



winds512tom
3 Mar 2010, 9:59 PM
append new child node to end of tree , the parent of the new child can't not collapse and expand , the code like this:

..........
var pid=Ext.getCmp('prdId').getValue();
var name=Ext.getCmp('prdlevelname').getValue();
var pnode = Ext.getCmp('prdTreePanel').getNodeById(pid);
// the child node can't show if the parent node collapse
pnode.expand(1,true,function(pnode){
// add child node
pnode.appendChild(new Ext.tree.TreeNode({id:id,text:name,leaf:true}));
//the parent node has not any child before append
pnode.attributes.leaf=false;
});
................

spidermanit
3 Mar 2010, 10:21 PM
Try this:


var pid=Ext.getCmp('prdId').getValue();
var name=Ext.getCmp('prdlevelname').getValue();
var pnode = Ext.getCmp('prdTreePanel').getNodeById(pid);
if(pnode){
pnode.appendChild(new Ext.tree.TreeNode({id:id,text:name,leaf:true}));
pnode.loaded = false;
pnode.expand(false);
}

Hope it works.

winds512tom
3 Mar 2010, 10:38 PM
same problem , the node not change when the child node append. the node has not been expand and collapse
my work result like :
http://b36.photo.store.qq.com/http_imgload.cgi?/rurl4_b=8792ea5a22e234a99ef04bc61d9cd68aec2a53d09da5ce446dc5d659ce4f50abf8a67d7a0fb7eda47303297959b2523c0b9f87aaeeaad64a0f7d1095171d18355c16ac79b527a9ee819864c67ce08123c8357de2&a=31&b=36