In ExtJs3, my team did the following to load data into a treestore. What's the equivalent way of doing this in ExtJS4? When I do similar code using a NodeInterface, I get a "Cannot read property '0' of null" error.
Ext.Ajax.request({
url: servlet,
success: function(response, opts)
{
var jsonData = Ext.decode(response.responseText);
var root = new Ext.tree.AsyncTreeNode({
text: 'Root test',
draggable: false,
id: 'root',
children: jsonData.tree.data
});
tree.setRootNode(root);
//...
Update: I don't really care how to get this done. I just have two requirements: (1) use a single server request to get unrelated data. (2) reuse treepanels and gridpanels for different data
I've been able to load the data into dynamically-created treepanels. However, using setRootNode() doesn't work with existing tree panels.
//this works
var tree = Ext.create('Ext.tree.Panel', {
root: {
text:'Application',
expanded:true,
children: jsonResponse.categoryTree.data
}
});
//this doesn't work
existingTree.setRootNode(root);
So far the "good enough" solution is to
Each time the data changes:
Not the "Ext JS 4" way but it gets the job done. Unless anyone can enlighten me with the correct way of doing things, I'm flagging this as the answer.
var panel = Ext.ComponentQuery.query('panel#categorysearch')[0];
//destroy the tree panel
panel.remove('categorysearchtree', true);
//create a new one
var tree = Ext.create('MyApp.view.CategorySearchTreePanel', {
root: {
text:'Services',
expanded:true,
children: jsonResponse.categoryTree.data
}
});
panel.add(tree);