欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ExtJS如何更新tree或grid的store

程序员文章站 2022-05-13 14:40:21
...
ExtJS并没有提供setStore()方法,但提供了reconfigure()方法,该方法继承自Ext.panel.Table,reconfigure方法API描述如下:
reconfigure( [Ext.data.Store store], [Object[] columns] )
Reconfigures the table with a new store/columns. Either the store or the columns can be ommitted if you don't wish to change them.

Parameters
store : Ext.data.Store (optional)
The new store.
columns : Object[] (optional)
An array of column configs

当然如果你能获取到组件的view,那么你也可以通过调用view的bindStore方法来改变store,
bindStore( Ext.data.Store store )
Changes the data store bound to this view and refreshes it.

但推荐使用reconfigure方法而不是bindStore, 原因:
reconfigure does a lot more than re-binding a store. If one has two stores of identical structure but merely wants to change the backing store for a grid, they need to get the store's Ext.grid.View by calling getView and call the bindStore method with the new store.
 
I would advise against that because it goes against the api and you might see some weird errors. I can see a potential problem arising when grid.getStore() != grid.getView().store I haven't run through the use case but grid.store.load() would not trigger a view refresh. reconfigure is designed to allow the grid to change stores and there isn't much overhead.

参考文档:http://*.com/questions/5884136/extjs-4-change-grid-store-on-the-fly