PDA

View Full Version : Moving AsyncTreeNode to a new parent



asagala
5 Oct 2010, 7:54 PM
I have tree structure like below using AsyncTreeNode and a treeloader

root
+-item1
+----item2
+------item3

Is it possible to replace item2 with a new node and then change item2 parent to the new node to have something like below without going through all the nodes or reloading the tree

root
+-item1
+----newnode
+------item2
+--------item3

I tried just swapping parent node but without success.



newnode = new Ext.tree.AsyncTreeNode(attributesofnewnode);
var item2= item1.firstChild; //gets item2

item1.appendChild(newnode);

item2.parentNode = newnode;

Condor
6 Oct 2010, 1:13 AM
You are not allowed to change parentNode (it's defined as read-only).

Just use appendChild again, e.g.

newnode.appendChild(item2);

asagala
6 Oct 2010, 6:21 AM
You are not allowed to change parentNode (it's defined as read-only).

Just use appendChild again, e.g.

newnode.appendChild(item2);

Tried that but it only appends item2 to newnode. I wanted to have item2 + all childnodes appended to newnode. I guess i will have to go through the childnodes one by one and append them back.

Condor
6 Oct 2010, 6:36 AM
item3 is a child of item2, so it should be moved together with item2! Are you saying that it doesn't?

Or does item1 have more children that need to be moved to newnode? That you have to do yourself.

asagala
6 Oct 2010, 6:48 AM
item3 is a child of item2 and its not being moved. Actually there could be item3 child of item2 and item4 child of item3 etc... They are AsyncTreeNodes. Could that make a difference?

asagala
6 Oct 2010, 7:21 AM
Actually I should be more precise. Item3 is not being moved and it actually disapear totally from the tree right after I append item2 to the newnode