Question: I am trying to add children tree nodes to a non-Root node dynamically when it's selected.

This is how I implemented it:

First, I populate my tree with a TreeStore then to dynamically add children tree nodes, I handle it on the itemexpand event in tree Controller.

```
//pThis is a NodeInterface obj of the selected node
itemexpand: function (pThis, pEOpts) {
      //type is an attribute that I added so that I know what type of node that got selected
      if (pThis.raw.type === 'Staff' && !pThis.hasChildNodes()) {
                    var staffNodeAry = [{text:"Teachers", type:"ChildStaff", leaf: false},
                                                     {text:"Principals", type:"ChildStaff", leaf: false}];          
                     pThis.appendChild(staffNodeAry); 
       }
}

```

This worked quite good because I am able to see both "Teachers" and "Principals" node under "Staff" type but there are 2 issues that I found so far:

1) There's this error on the console:

Uncaught TypeError: Cannot read property 'internalId' of undefined

I don't know why but if anyone could enlighten that would be great.

2) When I expand either "Teachers" and "Principals", the NodeInterface obj that's returned by itemexpand has an undefined raw object.

So I couldn't do this: pThis.raw.type

From my understanding, I don't need to create a new TreeStore to add any new children nodes, I thought that by creating an array of objects that adhere to NodeInterface should be enough but I might be wrong.
If anyone could point me to the right direction, that would be great.

Handi

**More info:**

What I did was actually following the ExtJs 4 documentation so I believe this is a bug on ExtJs 4 framework.

I also tested this with Extjs-4.1.0-rc3 and it also produced the same error.

Answer: 
I have resolved this issue changing the event **itemexpand** with the event **afteritemexpand**. I have no documentation to justify this. The debugger says to me that the view listen for the itemexpand event and do something that goes wrong if add a node manually...

For the question number 2: you have no raw object because it is created by the reader of the store after the load operation. So if you add a node by hand the raw object does not exists.

<http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Model-property-raw>
I think it happens because your Ext.TreePanel working asyncroniously. So add process is:

1. Append Child, add virtual child leaf to your tree, with red mark in corner
2. Call store's create api
3. Receive response, if it success=true, change with virtual

The goal of changing is set internakId property, so you can add new child only after this change happens. I think better is write some recursive function and bind it to store's added event

```
 tree.getStore().on('update', addChild);

```

or 

```
tree.getStore().load({
  success: function() { 
     addChild()
  });

```