I have an `itemexpand` listener in my treepanel. One of the parameters given to me is a `Ext.data.NodeInterface`. I am trying to add a child to this NodeInterface and have it use my Model, but I'm failing.

node.appendChild({
title:"This will NOT map to text, but will add node to tree"
});

node.appendChild({
text:"This will add a new node with text"
});

How do I add a child to a node in a tree and have it use the defined model for the store?

Another thing I've noticed is that the children attribute maps to the model, but the root does not.

node.appendChild({
title:"This will NOT map to text, but will add node to tree",
children:[
{
title:"This WILL map to text and will add node to tree"
}
]
});

sissonb

5 Sep 2012, 11:44 AM

Since this issue exists I was thinking about explicitly using my model before adding the data to the node. It looks like my model could be messed up though. I get the following when I try to use my model.

Field mapping is available for data reader only while convert() is available each time you set value to that field.

When you call <node>.appendChild() and supply its with nested data, then the following will happen:
1. The top most data will be used to construct a new node by using the respective model. This does not involve the data reader so field mapping will be ignored.

2. On node added, TreeStore will use its proxy data reader to extract all children of this node and at this period, field mapping has effect because data reader will use field mapping in extracting data.

3. With extracted data, TreeStore will call its fillNode() to append respective nodes to the node created in step 1 above.

I had a similar problem defining the root node in the tree store's config. Indeed, in this case, mapping seems to be ignored. I have fixed this issue using vietits solution but I haven't investigated deeper. Let me know if you need additional informations, I'll try to give you more details and some code. Version 4.2.1.883.