-
13 Jul 2012 4:37 AM #1
Switching between remote store and localstorage
Switching between remote store and localstorage
REQUIRED INFORMATION
Ext version tested:- Sencha Touch 2.x
- Chrome
- Android
- ____
- I am trying to switch between remotestorate and localstorage dynamically based on network connection.
- I am using setStore() method of list to switch between stores.
- I am defining store on list and before loading data, I am assigning store to list by using mylist.setStore(store)
The result that was expected:
The result that occurs instead:
Test Case:
Code:View: Ext.define('MyApp.view.MyList', {extend: 'Ext.List', xtype: 'MyListView', config: { itemTpl: {info} } }); Remote Store: Ext.define('MyApp.store.OnlineStore', {extend: 'Ext.data.Store', xtype: 'onlineStore', config: { autoLoad: false, clearOnPageLoad: false, model: 'MyApp.model.MyListModel', pageSize: 20, proxy: { type: 'jsonp', url: MyApp.util.Config.getServiceBaseUrl() + 'Data/GetInfo', reader: { type: 'json', rootProperty: 'Data', totalProperty: 'totalRecords' } } } }); Local Store: Ext.define('MyApp.store.OfflineStore', {extend: 'Ext.data.Store', xtype: 'offlineStore', requires: [ 'Ext.data.proxy.LocalStorage' ], config: { autoLoad: false, clearOnPageLoad: false, model: 'MyApp.model.MyListModel', pageSize: 20, proxy: { type: 'localstorage', id: 'MyApp-OfflineStore' } } }); Controller : //following is the logic to switch between stores on some event. if(isOnline){var myList = this.getMyList(); var remoteStore = Ext.getStore('OnlineStore'); myList.setStore(remoteStore ); } else{var myList = this.getMyList(); var offlineStore= Ext.getStore('OfflineStore'); myList.setStore(offlineStore); }
HELPFUL INFORMATION
Screenshot or Video
Possible fix:
Additional CSS used:- only default ext-all.css
Operating System:- Win 7
-
13 Jul 2012 4:55 AM #2
I think the dev team are going to want some more info, just a guess....!
You'll need to post an example I would have thought.
-
13 Jul 2012 6:49 AM #3
View:
Ext.define('MyApp.view.MyList', {extend: 'Ext.List',xtype: 'MyListView',config: {itemTpl: {info}}});
Remote Store:
Ext.define('MyApp.store.OnlineStore', {extend: 'Ext.data.Store',xtype: 'onlineStore',config: {autoLoad: false,clearOnPageLoad: false,model: 'MyApp.model.MyListModel',pageSize: 20,proxy: {type: 'jsonp',url: MyApp.util.Config.getServiceBaseUrl() + 'Data/GetInfo',reader: {type: 'json',rootProperty: 'Data',totalProperty: 'totalRecords'}}}});
Local Store:
Ext.define('MyApp.store.OfflineStore', {extend: 'Ext.data.Store',xtype: 'offlineStore',requires: ['Ext.data.proxy.LocalStorage'],config: {autoLoad: false,clearOnPageLoad: false,model: 'MyApp.model.MyListModel',pageSize: 20,proxy: {type: 'localstorage',id: 'MyApp-OfflineStore'}}});
Controller :
//following is the logic to switch between stores on some event.
if(isOnline){var myList = this.getMyList();var remoteStore = Ext.getStore('OnlineStore');myList.setStore(remoteStore );}
else{var myList = this.getMyList();var offlineStore= Ext.getStore('OfflineStore');myList.setStore(offlineStore);}
-
13 Jul 2012 7:06 AM #4
So as I thought this is has been correctly marked as inforeq and it's not a bug!
Read the docs before you post a bug report, you need to set the storeId, not the xtype, to be able to find the store using Ext.getStore.
-
13 Jul 2012 7:07 AM #5
I am able to get store correctly.
issue is after setting store it is not reflecting in view.
-
13 Jul 2012 7:09 AM #6
Are you sure??? Look below, you're providing a string to Ext.getStore. So that string would have to correspond with a store id. You're not setting store ids on your stores, so I can't believe you're getting a store returned by your Ext.getStore calls.
getStore( String/Object store ) : Ext.data.Store
Shortcut to Ext.data.StoreManager.lookup.
Gets a registered Store by id
Parameters
-
13 Jul 2012 7:11 AM #7
Yes I am getting store. as I am extending Ext.data.Store, we can get store by using Ext.getStore by providing class name
Wait! Looks like we don't have enough information to add this to bug database. Please follow this template bug format.


Reply With Quote