简体   繁体   English

Sencha Touch将功能添加到Sencha组件

[英]Sencha Touch add function to Sencha Component

I want to add a function to the Store Class for cleaning the store(proxy+data+sync), which I can call it via myStoreVariable.cleanAll(); 我想向商店类添加一个函数以清理商店(proxy + data + sync),我可以通过myStoreVariable.cleanAll();来调用它myStoreVariable.cleanAll(); or Ext.getStore('storeId').cleanAll(); Ext.getStore('storeId').cleanAll();

My first attempt is this, but I can't call this function from the store: 我的第一次尝试是这样,但是我不能从商店调用此函数:

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

My second attempt is this: 我的第二次尝试是:

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

It is working, but I don't want to define cleanAll for all of my stores. 它正在工作,但是我不想为我所有的商店定义cleanAll。

Do you know any possibility to add this function to the store class? 您知道将此功能添加到商店类的可能性吗? So I can call it from any store I create via Ext.create('Ext.data.Store', 因此,我可以在通过Ext.create('Ext.data.Store',

I found a way, overriding / adding a method to Ext.data.Store 我找到了一种方法,将方法覆盖/添加到Ext.data.Store

Put this code into your launch config of your Ext.Application 将此代码放入Ext.Application启动配置中

launch: function() {
    Ext.override(Ext.data.Store, {
        cleanAll: function() {
            this.getProxy().clear();
            this.data.clear();
            this.sync();
        }
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM