【问题标题】:Sencha Touch add function to Sencha ComponentSencha Touch 为 Sencha 组件添加功能
【发布时间】:2013-07-20 06:27:37
【问题描述】:

我想在 Store 类中添加一个函数来清理存储(代理+数据+同步),我可以通过 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',从我创建的任何商店调用它

【问题讨论】:

  • 您是否在定义自己的商店类?或者你只是实例化 Ext.data.Store?
  • 我只是在创建它们。 Ext.create('Ext.data.Store', { id: 'myId', model: 'myModel' });。但我想要所有商店的功能。
  • @sha 我更新了帖子。

标签: javascript extjs sencha-touch touch


【解决方案1】:

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

将此代码放入 Ext.Application 的启动配置中

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多