How to sync between stores in Sencha Touch

I have a Sencha Touch app that uploads data from a REST service to a repository using a REST proxy. The load event of this store also copies entries in the localstorage repository. This is due to the fact that the application must work offline. I am trying to write the changes made to the localstorage entries in the REST service, but could not figure out how to synchronize the localstorage storage and the storage using the REST proxy. Any ideas?

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

+7
source share
2 answers

You will need to implement something similar in the save event in your localstorage store that copies the changes to your onlineStore (similar to how you copy new items from onlineStore to offlineStore when it loads).

0
source

@Lyle Pratt is correct in that you have a function that is copied from your โ€œofflineโ€ store to your โ€œonlineโ€ store. But to expand it, I will create a function inside your offline storage 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 the same functionality for your online store in which it stores your online data in your offline storage.

0
source

All Articles