Sencha Touch为Sencha Component添加功能

时间:2013-07-19 21:52:03

标签: javascript extjs sencha-touch touch

我想在商店类中添加一个功能来清理商店(代理+数据+同步),我可以通过myStoreVariable.cleanAll();Ext.getStore('storeId').cleanAll();

来调用它

我的第一次尝试就是这个,但我无法从商店调用此功能:

Ext.data.Store.cleanAll = function() {
     this.getProxy().clear();
     this.data.clear();
     this.sync();
};

我的第二次尝试就是:

this.storeStore = Ext.create('Ext.data.Store', { id: 'myStore', model: 'myModel' });
this.storeStore.cleanAll = function() { /* my cleaning code(see above) */ };

它正在运作,但我不想为我的所有商店定义cleanAll。

您知道是否有可能将此功能添加到商店类?所以我可以通过Ext.create('Ext.data.Store',

从我创建的任何商店调用它

1 个答案:

答案 0 :(得分:0)

我找到了一种方法,覆盖/添加方法Ext.data.Store

将此代码放入Ext.Application

的启动配置中
launch: function() {
    Ext.override(Ext.data.Store, {
        cleanAll: function() {
            this.getProxy().clear();
            this.data.clear();
            this.sync();
        }
    });
}