PDA

View Full Version : Objects not removed from localStore (0.97)



peterkuli
21 Oct 2010, 5:25 AM
Hi everyone!

First of all; I'm new to Sencha Touch so I might not know everything yet.

I'm experimenting with localStore and am already able to store something in it. I use the developer tools of Chrome for debugging and if I look into Storage/Local Files I see the objects are stored as it should.


Ext.regModel('Assignment', {
fields: [
{name:'name', type:'string'}
]
});

var store = new Ext.data.Store({
proxy: new Ext.data.LocalStorageProxy({
id: 'test-assignment'
}),
model: 'Assignment'
});

Ext.setup({
onReady: function() {
store.add({name: 'test1' });
store.add({name: 'test2' });
store.sync();
//some more code

But now I'm trying to remove something from it:


store.remove(store.getAt(1));
store.sync();

When I look again at Storage/Local Files, I see that nothing's changed.

I don't think this issue (http://www.sencha.com/forum/showthread.php?110439-FIXED-339-LocalStore-Proxy-Record-Remove-Issue&highlight=destroy+localstorage) applies to me nor does this one (http://www.sencha.com/forum/showthread.php?108851-WebStorageProxy-always-removes-first-record).

herkulano
3 Nov 2010, 11:53 AM
i'm having the same problem in 0.98.

after remove() the data is really removed from the store.data, but after sync() nothing happens to the localstorage data!

mikermcneil
13 Apr 2011, 7:47 AM
Hey guys,

See chummy's post here:
http://www.sencha.com/forum/showthread.php?120074-Local-Storage-store.remove()-doesn-t-sync-Local-Store

The trick is to add an id field to your regModel:


// Set up local user state model template
User.template = Ext.regModel('User', {
fields: [
'id', // PROTECTED DONT TOUCH (stupid problem w/ sencha's LocalStore model)

// User identity
'user_id',
'secret',

// Personal info
'firstName',
'lastName',
'email',
'website',
'portrait_url',
'twitter_screen_name'
]
});

// Proxies
User.remoteProxy = new Ext.data.AjaxProxy({
model: 'User',
url: User.proxyURL,
reader: {
type: 'json'
},
type: 'ajax',
actionMethods: {
read: 'POST'
},
id: 'user_remote'
});
User.localProxy = new Ext.data.LocalStorageProxy({
model: 'User',
type: 'localstorage',
id: 'user_local'
});