简体   繁体   中英

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(); or 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.

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',

I found a way, overriding / adding a method to Ext.data.Store

Put this code into your launch config of your Ext.Application

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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