-
30 Jul 2012 6:22 PM #1
Unanswered: Yet another question about Localstorage
Unanswered: Yet another question about Localstorage
Hello,
I have problems with saving or loading data to/from localstorage. After adding record, I can view it in the dataview. But when I'm restarting application there is no data, also if I use myStore.load() function to reload data in dataview, it will not load any data from localstorage and will nullify store.
adding new record:
my store:Code:var myStore= Ext.data.StoreManager.lookup('MyImageStore'); myStore.add({id:(max+1),caption:cap,name:idName,date:dat,path:local_path}); myStore.sync();
dataview:Code:Ext.define('ws.store.MyImageStore', { extend: 'Ext.data.Store', xtype: 'MyImageStore', requires: 'ws.model.ImageModel', config: { model: 'ws.model.ImageModel', proxy: { type: 'localstorage', id : 'myImageLocalstorage' } }, autoLoad: true });
and refresh function:Code:Ext.define('ws.view.Nav', { extend: 'Ext.DataView', xtype: 'Nav', config: { store: 'MyImageStore', itemTpl: '<div>{name}|{caption}|{date}|{path}</div>' } });
Code:var datav=Ext.getCmp("Nav"); datav.refresh();
-
31 Jul 2012 6:20 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- Frederick MD, NYC, DC
- Posts
- 16,169
- Vote Rating
- 28
- Answers
- 83
Welcome to the forums
.
Here are some suggestions:
1) STOP using static IDs
2) you need to use store.add() to add an instance of a model, not a plain object.
3) local storage proxies need to be setup on the model, not the store.
4) Look at the LocalStorage proxy for an example: http://docs.sencha.com/touch/2-0/#!/...y.LocalStorage
it works perfectly.
Jay Garcia @ModusJesus || Modus Create co-founder
Ext JS in Action author
Sencha Touch in Action author
Get in touch for Ext JS & Sencha Touch Touch Training
We are also working on Video-based Sencha Touch training: Check it out here.
-
1 Aug 2012 6:15 AM #3Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3109
If you use a config object like the OP does it will create the model instance (record) and add that so it's still very much valid to do like he did:
Matter of preference for local storage, very much valid to put it on the store.Code:myStore.add({ id : (max + 1), caption : cap, name : idName, date : dat, path : local_path });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.


Reply With Quote