-
5 Nov 2012 3:12 AM #1
Unanswered: Dynamically-created Local Storage store not in StoreManager
Unanswered: Dynamically-created Local Storage store not in StoreManager
Hello all,
I'm having a nightmare with local storage as I already have another post up related to LS.
This one is about a dynamically-created store not being persistent. Elsewhere in my app, because I have a local storage store instantiated in the app.js store:[] section, this IS persistent on page refresh.
However, when I try to load data into a store which is not being instantiated in the app.js store:[] section, I can't load the data after page refresh.
Code:
Model:
Store:Code:Ext.define('App.model.Region', { extend: 'Ext.data.Model', requires: ['Ext.data.identifier.Uuid'], config: { idProperty: 'auto', fields: ['id','buildingName','town','agent'], identifier: 'uuid' } });
Store creation:Code:Ext.define('App.store.Region', { extend: 'Ext.data.Store', alias: 'store.region', requires: ['Ext.data.proxy.LocalStorage'], config: { storeId: 'region', model: 'App.model.Region', autoSave: false, syncRemovedRecords: false } });
Code:Ext.getStore('Store1').load({ // Create localstorage store Ext.create('App.store.Region', { storeId: 'rg-46677', autoLoad: true, autoSave: true, proxy: { type: 'localstorage', storeId: 'rg-46677', } }) regionStore = Ext.getStore('rg-46677'); // Load data from Store1 into the localstorage store Ext.each(this.getData().items, function(rec) { regionStore.add(rec); }) regionStore.sync(); //Bind to list listComp.setStore(regionStore); })
I'm assuming that it's because it is not getting registered in the StoreManager as it is not in Ext.data.StoreManager.all?
Any help would be greatly appreciated.
Thanks,
George
P.s.
(I have also looked here http://www.sencha.com/forum/showthre...nd-persistency but I am already using that method).
-
7 Nov 2012 4:58 AM #2
Sorry to bump the thread but it's grinding my gears now and could I do with the help.
I've just upgraded from 2.0.1.1 to 2.1 and the problem is persisting.
-
7 Nov 2012 6:25 AM #3Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
- Answers
- 3102
How are you requiring the store?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
7 Nov 2012 6:27 AM #4
Well I'm saving it in a localstorage store so that if the app is offline, it is still accessible. But like I said, the dynamically created store doesn't work on refresh, whereas the other store that is local storage which is in the Ext.application() store[] section is.
-
7 Nov 2012 6:32 AM #5Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
- Answers
- 3102
If the store is in the stores array in Ext.application then an instance will be created automatically. It will either use the storeId config if one is present or create a storeId based on the class name.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
7 Nov 2012 6:44 AM #6
That's the problem, it isn't in the stores array.
I have created a store called Region, which IS in the store array:
Code:Ext.define('Audit.store.Region', { extend: 'Ext.data.Store', requires: ['Ext.data.proxy.LocalStorage'], config: { model: 'Audit.model.Region', sorters: 'region', proxy: { type: 'localstorage', id: 'region-main' } } });
Then in my view, I have a selectfield with different regions in, once I select a region, I make an ajax request to get a feed for that region. I then store this feed in a localstorage store by 'extending'(not sure if that is the write term) the original 'Region' store:
It is this dynamically-created store that isn't saved. And I will have numerous stores like this.Code:Ext.getStore('Region').setProxy( code here points to a file and gets the relevant feed ).load({ // 'This is where I 'extend' that store already in the Ext.application store[] config // itemtosearch is a number that I use to load the relevant file Ext.create('Audit.store.Region', { storeId: 'rg-'+itemToSearch, proxy: { type: 'localstorage', id: 'rg-'+itemToSearch } }) regionStore = Ext.getStore('rg-'+itemToSearch); Ext.each(this.getData().items, function(rec) { var recToAdd = rec.data; delete recToAdd['auto']; delete recToAdd['id']; console.log(recToAdd); regionStore.add(recToAdd); }) regionStore.sync(); })
Should I just load all data into the store that is in the store:[] config and just filter it per region?
-
7 Nov 2012 7:01 AM #7Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
- Answers
- 3102
This is working for me:
However, in your code you don't need to do the getStore call.Code:Ext.create('Ext.data.Store', { fields : ['test'], storeId : 'test', proxy : { type : 'localstorage', id : 'test' } }); console.log(Ext.getStore('test'));Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
7 Nov 2012 7:10 AM #8
Still isn't working for me, is it still there on refresh for you?
I've changed it to the following but isn't playing ball still..
Code:Ext.create('Ext.data.Store', { model: 'Audit.model.Region', storeId: 'rg-'+itemToSearch, proxy: { type: 'localstorage', id: 'rg-'+itemToSearch } })


Reply With Quote