PDA

View Full Version : How to update existing record in localstorage store



kostysh
13 Dec 2011, 8:26 PM
Hi,
I have problem with updating of existing record in localstorage store.
Adding a new records with:


store.add(newRecord);

store.sync();


- no problem.
But if I try update already created record:


var record = store.findRecord('id', createdId);

record.set(updatedRecord); //updatedRecord is key-value object with new record


- error:
Uncaught TypeError: Cannot call method 'update' of undefined (in PR3 ST2)
and
Uncaught TypeError: Cannot read property 'isModel' of undefined (in PR2 ST2)

Where it may be my mistake?

mitchellsimoens
14 Dec 2011, 6:28 AM
local storage has been a little broken. This will get fixed before way before GA

kostysh
14 Dec 2011, 7:11 AM
hmm.. it is a pity
perhaps there is a patch to fix the problem until the next release?

Martin1982
22 Dec 2011, 2:46 PM
Is there any other way to locally store data at the moment? I'm really in need of this :-?

rdougan
22 Dec 2011, 3:10 PM
You'd have to implement your own version of it, which wouldn't be too difficult.

germallon
17 May 2012, 5:46 AM
I see there is no activity in this thread since December. Any updates on this?

kostysh
17 May 2012, 7:20 AM
All works fine for now

germallon
17 May 2012, 7:28 AM
Perhaps I didn't explain myself correctly. Is there a way to update the localStorage records? Something along the lines of:

record.update({fieldkey:fieldval, ...})?

I know you can use record.setData({...}), but what if you have a record with several fields, and you are interested in updating only a few of those fields?

Thank you in advance.

kostysh
17 May 2012, 7:47 AM
http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Store-method-add



storeObj.add({field: 'value'});
storeObj.sync();// Or setup autoSync: true in store config

germallon
17 May 2012, 7:55 AM
http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Store-method-add



storeObj.add({field: 'value'});
storeObj.sync();// Or setup autoSync: true in store config


Correct me if I'm wrong, but your code snippet adds a new record to the store. It does not update an existing record.

kostysh
17 May 2012, 8:15 AM
Yes, you right.


Code below shows howto update record in store:


var record = storeObj.getAt(0);// Or use findRecord
record.set({field: 'value'});
storeObj.sync();

germallon
17 May 2012, 10:20 AM
Thanks..

This is what I mean.

Suppose at one point I did something like this:
myStore.add({field1: 'val1', field2: 'val2', ..., fieldn: 'valn' });
And I needed to update one of the fields in that record, but leave the rest of the fields intact. I'd like to be able to do something along the lines of:


var rec = myStore.getById(myRecId);
rec.update({fieldx: 'valuex'})
myStore.sync();


I guess what I'm looking for doesn't exists. But it'd be a great feature to have.

riyaad
16 Sep 2013, 1:38 AM
Hi guys, any update or resolution regarding this one? Would be appreciated (code sample or link etc.).
Thank you ~o)