问题
how to refresh a Tree Store ?
I tried to do like that:
Ext.getStore('myStore').setRootNode({child: []});
And then the Store will request the Server to have children but sometimes it gives me a child in double. In my Tree I get something like:
child1
child2
child1
and there is also a javascript error:
Uncaught TypeError: Cannot read property 'internalId' of undefined
Ext.define.updateIndexes ext-all-debug.js:61588
Ext.define.onAdd ext-all-debug.js:61513
Base.implement.callParent ext-all-debug.js:3728
Is it a bug or am I doing something wrong ?
回答1:
I'm not sure what version of extjs you're using but here's how I refresh my store in 4.1 using the load method (you may or may not have parameters, I have one):
this.getStore('MyTreeStore').load({ params: { id: this.getId().getValue()} });
The store is refreshed with new records with no duplicates from any previous load.
I have my store setup like so:
Ext.define('MyApp.store.MyTreeStore', {
extend: 'Ext.data.TreeStore',
model: 'MyApp.model.MyTreeModel',
root: {
children: []
},
proxy: {
type: 'ajax',
url: '/MyApp/Chart/GetTree'
},
fields: [
{ name: 'id', type: 'int' }
]
});
and my Tree looks like this:
Ext.define('MyApp.view.chart.MyTree', {
extend: 'Ext.tree.Panel',
alias: 'widget.mytree',
id: 'MyTree',
store: 'MyTreeStore',
width: 350,
height: 320,
border: false,
rootVisible: false,
singleExpand: true
});
来源:https://stackoverflow.com/questions/10539662/extjs-refresh-tree-store