PDA

View Full Version : Updating a stored item replicates index key - Sencha Touch 1.0



francescosyd
27 Dec 2010, 4:10 AM
Hi all,

I'm not sure if this behaviour is by design or a bug but when I update a stored record/item the item key seems to repeatedly append to the indexer value.

To update a record/stored item I'm using the following code:

var storeItem = myComponent.store.getById(373557);
storeItem .set('test', "hello in there");
//store.dirty = true;
storeItem.store.sync();

//model
Ext.regModel("Conversation", {
fields: [
{ name: "id", type: "int" },
{ name: "test", type: "string" }]
});

//store
Ext.regStore('Conversations', {
model: 'Conversation',
storeId: 'conversationsStore',
autoLoad: true,
autoSave: true //tried on and off, didn't make a difference
});


Viewing local storage files in Google Chrome I see that the value in key conversations-373557 is set correctly, however the value for the indexer conversations is '373557,373557,373557'. (Here I've updated a value in the record/item twice)

Each time I update the record/item and sync it the id for my record/item is appended to the indexer.

23980

Does anyone know if this is a bug, by design or am I doing something wrong?

thanks

Francesco

clabasky
21 Sep 2011, 3:00 PM
hey I'm working on a similar problem now, did you ever figure it out?

Schaden
29 Sep 2011, 8:35 PM
Me too. Did you ever get anywhere with it?

francescosyd
12 Oct 2011, 9:19 PM
Hi guys, stopped using the sencha stores and just wrote my own JSON serializer/de-serializer to local storage.

Here are my utility methods:


saveData : function(key, data, asJSON) {
if (!Ext.isDefined(asJSON))
asJSON = false;
localStorage.setItem(localStoragePrefix + key, (asJSON)
? Ext.util.JSON.encode(data)
: data);
},


getData : function(key, asJSON) {
if (!Ext.isDefined(asJSON))
asJSON = false;
var data = localStorage.getItem(localStoragePrefix + key);
if (data != null && asJSON)
data = Ext.util.JSON.decode(data);
return data;
},


deleteData : function(key) {
localStorage.removeItem(localStoragePrefix + key);
},


clearAllData : function() {
var keyLength = localStoragePrefix.length;
console.log(keyLength);
for (key in localStorage) {
console.log(localStorage);
if (key.substring(0, keyLength) === localStoragePrefix)
localStorage.removeItem(key);
}
}


cheers

Francesco