I have a tree with an ajax store like this:
Code:
var tree = Ext.create('Ext.tree.Panel', {
model: 'TreeModel',
store: store,
...
with this store and model:
Code:
var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: '../api/tree'
},
root: {
text: 'Root',
expanded: true
},
sorters: [{
property: 'text',
direction: 'ASC'
}]
});
Code:
Ext.define('TreeModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'string' },
{ name: 'text', type: 'string',},
{ name: 'entity', type: 'string' }
]
});
By collapsing the nodes I sending a new request to my api-server. If the result is empty, I want to add a child node. For this I create a model instance, a node and trying to add them with appendChild, but it didn't work?
Code:
var testRecord = Ext.create('TreeModel', {
id: 'testId',
text: 'testText',
entity: 'testEntity'
});
In the 'afteritemexpand' listener at the tree I create and append the node:
Code:
var myNode = node.createNode(testRecord);
node.appendChild(myNode);
What's wrong in my code?