PDA

View Full Version : add nodes dynamically



xmart2k
17 Jul 2008, 2:09 AM
i have a tree with an image button for each node, when i click the image i want to add a child node to the current node.
my code

listeners : {
click: function(n,el) {
if (el.target.className == 'add'){
var newNode = {text:'test',leaf:true,id:999};
n.appendChild(newNode);
}
}
},but i got this error

node.setOwnerTree is not a function
node.setOwnerTree(this.getOwnerTree());

this is how my tree looks, i'm trying to add to the "My stuff" node
8153

Animal
17 Jul 2008, 2:25 AM
You cannot just add a Javascript object, you must add a new Ext.tree.TreeNode()

xmart2k
17 Jul 2008, 2:50 AM
thanks, it worked, but now i got another problem, the node is added only if i first collapse the node that will be parent for the new one, then click the image. how can i add the node even if the root node was not collapsed yet.

thanks in advance

xmart2k
17 Jul 2008, 3:24 AM
i've found a solution, i'll expand the node first.

another question: how do i make a leaf to become a root, how do i add the expand +

thanks

Animal
17 Jul 2008, 3:55 AM
leaf: false

xmart2k
17 Jul 2008, 4:29 AM
thanks