7
votes

I have a Sencha Touch App that loads data from a REST service into a store using a REST proxy. The load event of this store also copies the records into a localstorage store. This is because the app needs to work in an offline mode. I am trying to write back changes made to records in the localstorage to the REST service, but haven't managed to figure out how to sync the localstorage store and the store that uses the REST proxy. Any ideas?

I followed the example given here http://www.sencha.com/learn/taking-sencha-touch-apps-offline/ , but it covers only read-only scenarios for offline data.

2
Did you find a way to do this.?Konza

2 Answers

0
votes

You'll need to implement something similar in the save event on your localstorage store that copies changes over to your onlineStore (much like you're copying new items from your onlineStore to the offlineStore when it loads).

0
votes

@Lyle Pratt is correct about having a functionality that copy from your "offline" store to your "online" store. But to expand it more, I will create a function inside your offline store where it will save or copy your offline data to your online store.

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

    }
});

On the other hand, you can also create a same functionality for your online store wherein it will save your online data to your offline store.