View Full Version : Changing value of attribute, of record in localstorage.

4 Oct 2010, 3:11 AM
I am using a localstorage to save several records called orders. When I first load those into the store (via web services and a php proxy) I can just alter one of the attributes (with set) of an order/record and it synchs normally.

When I reload my browser, the store reads all the orders from localstorage. But when I try to change one of the attributes and synch it with the localstorage, it gets saved as new (id undefined) record. So when I reload my app again, it gives a big Uncaught TypeError: Cannot read property 'orderid' of null error.

The first time I alter an attribute (I have just loaded the data into the store and localstorage) there is no error. The second time, after I have loaded the records from localstorage into the store, I alter an attribute, the record gets saved as a new record.

Am I doing something wrong or is this a bug?

4 Oct 2010, 3:54 AM
I have been experimenting the same problems with the localStorage since 0.96... i don't know about 0.95, but on 0.94 everything was working fine... and now it seems that the framework is having problems with "updates"... and sometimes (very randomly) even with removals...

4 Oct 2010, 5:55 AM
An added note, to clarify:

There is something wrong with the id of a record in the localstorage.
When I load records from the localstorage in a store and then sync the store, the variable which contains all id of the records has double the normal id's and the new halve is not an int but 'NaN'.
So there is a bug that prevents localstorage to recognize the records as existing records.

This is because when the store reads the data/records from the localstorage, it doesn't set the ID of the record in the store.

Will this be fixed soon, or I am doing it completely wrong?

4 Oct 2010, 6:16 AM
I believe I have a solution. Like I said in my former post, the problem is with the ID.
So you add an variable 'id' to the model you use for the store.

When you do that, and the store reads the records from localstorage, the 'id' will be set and you can use it to update, delete,...

name: 'id',
type: 'integer'

But a point of annoyance. The localstorage variable/record which contains all the keys of the records of a store, adds the id's to the existing id's. So when you have you have two records and you have edited them a few times, the variable which contains the id's will look something like:'1,2,1,2,1,2,1,2' But this doesn't interfer with the reading and updating.

It does interfer with removing.