【问题标题】:How do I sync between stores in Sencha Touch如何在 Sencha Touch 中的商店之间同步
【发布时间】:2011-07-25 06:55:15
【问题描述】:

我有一个 Sencha Touch 应用程序,它使用 REST 代理将数据从 REST 服务加载到存储中。此存储的加载事件还将记录复制到本地存储存储中。这是因为应用程序需要在离线模式下工作。我正在尝试将对 localstorage 中的记录所做的更改写回 REST 服务,但还没有设法弄清楚如何同步 localstorage 存储和使用 REST 代理的存储。有什么想法吗?

我按照此处给出的示例 http://www.sencha.com/learn/taking-sencha-touch-apps-offline/ 进行操作,但它仅涵盖离线数据的只读场景。

【问题讨论】:

  • 你找到办法了吗?

标签: sencha-touch extjs


【解决方案1】:

您需要在 localstorage 商店的保存事件中实现类似的操作,将更改复制到您的 onlineStore(就像您将新项目从 onlineStore 复制到 offlineStore 时一样它加载)。

【讨论】:

    【解决方案2】:

    @Lyle Pratt 关于拥有从“离线”商店复制到“在线”商店的功能是正确的。但为了进一步扩展它,我将在您的离线商店中创建一个函数,它将您的离线数据保存或复制到您的在线商店。

    Ext.define('MyProject.store.OfflineMessage', {
        config: {
            model: 'MyProject.model.Message' //this should be the same with your online store
    
        },
    
        sync: function(){
            var me = this, 
                onlineMessageStore = Ext.getStore('OnlineMessage'), //you can get your current store or just create a new one
                items = me.getData().items; 
    
            onlineMessageStore.setData(items);
            onlineMessageStore.sync();
    
        }
    });
    

    另一方面,您也可以为您的在线商店创建相同的功能,它将您的在线数据保存到您的离线商店。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-29
      • 1970-01-01
      • 1970-01-01
      • 2012-06-17
      • 2013-04-16
      • 2011-09-01
      • 2014-03-03
      • 2014-01-25
      相关资源
      最近更新 更多