ExtJS如何更新tree或grid的store

[size=medium]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.

参考文档:[url]http://stackoverflow.com/questions/5884136/extjs-4-change-grid-store-on-the-fly[/url][/size]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值