PDA

View Full Version : localstorage empty after browser refresh



macs
17 May 2012, 5:24 AM
i am using a store with a localstorage proxy which i configured like below.


Ext.define('VB1.store.FavoritesStore', {
extend: 'Ext.data.Store',
alias: 'widget.favoritesstore',
config: {
storeId: 'vbFavoritesStore'',
model: 'VB1.model.myModel',
autoLoad: false,
proxy: {
type: 'localstorage',
id: 'favprodproxy'
}
},
});

adding items to the store and view the is no problem, however, when i refresh the browser (chrome) the store is empty again. Is there anything i overlook? thanks a lot for any suggestions

mitchellsimoens
19 May 2012, 2:53 PM
Do you load the store?

macs
20 May 2012, 6:33 AM
no. i noticed previously that when i do this the store gets emptied even without page refresh.

macs
20 May 2012, 6:45 AM
no. i tried that before but that seems to empty the store even without page refresh. in the chrome console under resources i can see that there is a local storage object named after the proxys id (which is still there after page refresh). however this object seems to have no value. hence the store has data (since i can display it), the localstorage object in the console is empty however before and after the page refresh.

Skynet-tx
24 May 2012, 2:53 AM
Hi! I have same problem. macs, how you decided this problem? Can you answer fully?

macs
28 May 2012, 8:20 AM
not solved yet! sorry Skynet-tx. let me know if you find a solution

Möhre
30 May 2012, 4:53 AM
ST 2.0.0 or 2.0.1?

I always use
autoLoad: true,
autoSync: true,

which works fine.

I think you will not get an answer or solution here if you won´t post your full source or a simplified example.

Skynet-tx
30 May 2012, 5:42 AM
I done it, how write above. Also, be sure to register types of data fields, without this will not work! ;)

DeepShah
31 May 2012, 11:44 PM
It will work :

put below lines in your store -

autoLoad: true,
autoSync: true,

blaise35
1 Jun 2012, 12:01 AM
Hi,

Make sure you let the store manage id generation of your objects. I had this bug and resolved it by letting the store manage the ids.


fields: ['id', 'nid', 'thumb', 'title', 'surface', 'chambres', 'secteur', 'prix']

nid is my own id and i added the id field.

Hope it help.

Blaise

hebr3
1 Jun 2012, 2:34 AM
I also had problems with this when I started to use it a few weeks ago. Since I was (and I am still) in a steep learning curve, I am not sure that my problem was same. Anyway I was able to solve my issue:
I found this release note for Sencha Touch 2
If you are using a LocalStorage proxy, from now on your Model's identifier strategy must generate unique id's. We suggest you use the included UUID strategy by adding identifier: 'uuid' to your Model definition. Any existing Models you have saved to LocalStorage will need to have this added. A warning will be thrown for any Model configured with a LocalStorage proxy that doesn't have a unique id generating strategy.
So I added in the model "identifier: 'uuid". This solved my problem.
Maybe it is worth a try...

macs
3 Jun 2012, 10:13 AM
thanks everybody for the suggestions. i tried them all, however, although i can store data in the localstore once i reload he page the store is empty again:

here is my code

the store:


Ext.define('VB1.store.prod.FavProdStore', {
extend: 'Ext.data.Store',
alias: 'widget.favprodstore',
config: {
storeId: 'vbFavProdStore',
model: 'VB1.model.prod.FavProdModel',
autoLoad: true,
autoSync: true,
proxy: {
type: 'localstorage',
id: 'favprodproxy'
}
},
});

my model:


Ext.define('VB1.model.prod.FavProdModel', {
extend: 'Ext.data.Model',
config: {
identifier: 'uuid',
fields: [
{name: 'id'},
{name: 'mid', type: 'string'},
{name: 'shop_id', type: 'string'},
{name: 'title', type: 'string'},
{name: 'lat', type: 'float'},
{name: 'lng', type: 'float'},
{name: 'distance', type: 'float'},
],
},
});

this is how i dd items to the store


addFavorite: function () {
var prodDetails = this.getProdDetailView().getData(),
favData = this.favprodstore.findRecord('mid',prodDetails.mid);
if (!favData) {
this.favprodstore.add(prodDetails);
this.favprodstore.sync();
var dataCount = this.favprodstore.getCount();
this.getFavButton().setBadgeText(dataCount);
} else {
this.showAlreadyIn();
}
},

is anyone spotting what is wrong here?

macs
25 Jun 2012, 9:59 AM
i solved it. thanks for all the suggestions. it had to to with how other models that i was using were configured. basically the problem was that no unique identifier strategy was applied

duranmla
13 Aug 2012, 8:24 PM
I solved the problem adding the idProperty: 'id' to my store, this line say to the browser a way to find the data that we save ^^ you dont need have a id field this value is generated automatically ('i think so', you can see this into console>resources>localstorage (chrome))