PDA

View Full Version : LocalStorageProxy with id-field doesn't work



preyz
8 May 2011, 9:44 AM
I'm trying to replicate Cookie-functionailty with a LocalStorage. For this purpose I have a Model called "Cookie" and a Store called "app.stores.cookies". When I try to load() the store with saved data, it returns the following error: TypeError: Result of expression 'rawData' [null] is not an object.


Ext.regModel('Cookie', {
fields: ['id', 'value'],
proxy: {
type: 'localstorage',
id: 'cookies'
}
});

app.stores.cookies = new Ext.data.Store({
model: "Cookie",
});


// No data stored => No error...
app.stores.cookies.load();

// Add an entry...
app.stores.cookies.add({id:key, value:value});

// Page-reload or next visit to page. I want to retrieve the data, but get the error mentioned above.
app.stores.cookies.load();

It is possible to work around this, by using another field (for example call it "key") and filters when accessing the stored data. However, this defeats the purpose of non-integer ID's, which should work just as fine.

preyz
8 May 2011, 11:52 PM
I've created a plugin that provides cookie-functionality, working around the problem above using key/value fields in the cookie-model, instead of id/value: http://www.sencha.com/forum/showthread.php?132816-Cookie-Plugin-for-Sencha-Touch-(using-LocalStorage)

mitchellsimoens
9 May 2011, 7:11 AM
Currently IDs for LocalStorageProxy have to be int. I made an override to fix this.

Mis63
20 May 2011, 6:39 AM
How can we get the fix ?
It is a blocking point for me.
Thanks

mitchellsimoens
20 May 2011, 6:43 AM
How can we get the fix ?
It is a blocking point for me.
Thanks

http://www.sencha.com/forum/showthread.php?127037-1.1.0-Id-in-WebStorageProxy-does-not-need-to-be-int

Don't like my eliminateDuplicates method but it works for now.