PDA

View Full Version : Treepanels and Records



Voyd
13 Mar 2012, 7:24 AM
In a nut shell, I need two separate tree panels using / pointing to the same record. Currently, once I give the record to one of the trees, it becomes a "node" and cannot be given to the second tree. Not only is it a node on the tree, but the basic store I am using to pull that record from is also being changed to a node. Is there a way around this? I need to be able to call my addPerson method on two different trees with the same "person" record, somehow the decorate method is permanently changing the record into a node in all places, which I do not want.

addPerson : function(rootNode, person) {
person = Ext.data.NodeInterface.decorate(person);
person.set('text', person.getName());
person.data.type = PERSON_FOLDER;
person.data.leaf = false;
var personAddedToTree = rootNode.appendChild(person);
return personAddedToTree;
}

mitchellsimoens
13 Mar 2012, 10:48 AM
You can get the node and get the data from it to create a new node for the other store.

Voyd
14 Mar 2012, 2:31 PM
Do you mean that you are copying the data first? And then creating a new node from that? I want to use the SAME record for both treepanels. I want to use a MVC pattern where a data model instance is displayed in two different views, those being in this case treepanels. Currently, when a data model instance (record) is decorated as a "tree node" it can only be appended to one tree at a time. In other words, a child node can only have one parent node. I went around this by giving each node a reference to the record it needs, and gave the record a reference to the nodes. This is an anti-pattern as I had to couple the model to the view. So, what to do?