PDA

View Full Version : setRootNode on a tree panel bashes the old root node?



bimargulies
11 Aug 2012, 5:17 PM
Using ExtJS 4.1.1:

First, I pass a tree of nodes into my TreePanel with setRootNode.

Then, I pass a new tree via the same call. To my distress, I find that this appears to modify the old root node to be empty. Since I'm trying to save/restore the contents of a tree panel, this doesn't work so well.

Is there a better approach to saving and restoring the contents of a TreePanel other than to try to pass the same objects into setRootNode?

I have created a complete test case for this: find it at:

https://github.com/basis-technology-corp/ext-js-tree-destruction.git

vietits
12 Aug 2012, 4:52 PM
Your problem is that the data object you passed to <treepanel>.setRootNode() will be modified. After calling setRootNode(), its value is not the same as before.


var rootData = {...};
tree.setRootNode(rootData); <- this will modify rootData variable

One way to fix this problem is to clone your data object before calling setRootNode(). For example:


var rootData = {...};
tree.setRootNode(Ext.clone(rootData));