PDA

View Full Version : Appending nodes to Tree Panel and accessing custom data



jclark42796
26 Apr 2012, 10:47 AM
We're upgrading from 4.0.7 to 4.1.

I have an Ext.tree.Panel where I'm building the nodes dynamically. In 4.0.7 I was able to do something like the following:


myTree.getRootNode().appendChild({
text: 'hello',
leaf: true,
typeId: someId,
definition: {prop1: 'a', prop2: 'b'} // some custom data I want accessible later
});

Later, in a select node callback, I could receive the selected node and inspect the 'definition' property.

In 4.1 I'm no longer able to access these custom properties, .e.g "definition". It appears as if the object passed to appendChild needs to be a "model". Since it's not a model, it's converted to one. In this conversion a data property is created, but my custom property is not added. This seems due to a predefined list of field names, e.g text, parentId, etc.

How do I append this child node and have access to my custom property as I did in 4.0.7?

Thanks,
Jim

vietits
26 Apr 2012, 3:32 PM
There are some solutions for this issue:

1. Add 'definition' as a field in your model definition

fields: [{
...
},{
name: 'definition', type: 'auto'
}]
...

2.


var node = myTree.getRootNode().appendChild({
text: 'hello',
leaf: true,
typeId: someId,
// definition: {prop1: 'a', prop2: 'b'} // some custom data I want accessible later
});
node.definition = {prop1: 'a', prop2: 'b'};

To access custom data


var definition = <node>.definition;

jclark42796
27 Apr 2012, 8:02 AM
Hi, thanks for the suggestions. I went with suggestion #2 and that worked. I appreciate it :)

Jim