-
2 Jun 2012 7:03 AM #1
Localstore proxy not removing indexes after records deleted
Localstore proxy not removing indexes after records deleted
Sencha Touch version tested:
- Sencha Touch 2.0.0
- Google Chrome (21.0.1155.2 dev)
I am having some trouble with a Sencha Touch data store and a localproxy. Basically, when a record is removed from the store, using the store.remove(record) method, the record itself is removed from memory, but the Id reference to it in the store is not removed, so when the page is refreshed, I receive a lovely "Uncaught TypeError: Cannot read property 'isModel' of undefined"
Steps to reproduce the problem:- Create a store, with a localstorage proxy
- Add at least 2 items to the store
- Remove one of them using store.remove(record) method
- The record is removed from localstorage, and the Id removed from the localstore.
- The record is removed from localstorage, but the id is not removed from the store itself, so when the page is refreshed, the store throws an undefined exception
Here is the code for the store:
Code:Ext.define("App.store.Data", { extend: "Ext.data.Store", requires: "Ext.data.proxy.LocalStorage", config: { model: "App.model.Data", autoSync: true, proxy: { type: 'localstorage', id: 'app-store' } } });Here is the code for the delete button on the data editor page
Screenshot:Code:onDeleteHomeworkCommand: function () { var dataEditor = this.getDataEditor(); var currentData = dataEditor.getRecord(); var dataStore = Ext.getStore("Data"); dataStore.remove(currentData); dataStore.sync(); this.activateDataList(); },- Before the record is removed: http://i.imgur.com/HmOtT.png
- After the record is removed: http://i.imgur.com/VEmeq.png
- Manual removal of Ids from data store
- Somehow get the data store to sync
Additional CSS used:- only default
Operating System:- Mac OSX 10.7.3
-
4 Jun 2012 5:00 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 435
The id item in localStorage gets removed for me using this test case using 2.0.0 and 2.0.1:
Code:/** * This has been tested with ST 2.0.1 * * This shows localstorage adding, removing, and loading */ Ext.define('TestModel', { extend : 'Ext.data.Model', config : { identifier : 'uuid', fields : [ 'test' ] } }); var store = new Ext.data.Store({ autoLoad : true, model : 'TestModel', proxy : { type : 'localstorage', id : 'test' }, listeners : { load : function (s) { console.log('Data loaded, store has ' + s.getCount() + ' items'); } } }); new Ext.Container({ fullscreen : true, items : [ { xtype : 'button', text : 'Add Data', handler : function () { store.add([ { test : 'One' }, { test : 'Two' }, { test : 'Three' } ]); store.sync(); console.log('Data added, store has ' + store.getCount() + ' items'); } }, { xtype : 'button', text : 'Remove First Record', handler : function () { var rec = store.getAt(0); store.remove(rec); store.sync(); console.log('First record removed, store has ' + store.getCount() + ' items'); } }, { xtype : 'button', text : 'Clear Data', handler : function () { store.removeAll(); store.sync(); console.log('Data cleared, store has ' + store.getCount() + ' items'); } }, { xtype : 'button', text : 'Remove At Index', handler : function () { Ext.Msg.prompt('Index', 'What index to remove?', function (btn, index) { if (btn === 'ok') { store.removeAt(index); store.sync(); console.log('Record removed at index ' + index + '. Store has ' + store.getCount() + ' items') } }); } }, { xtype : 'button', text : 'Console Record Data', handler : function () { console.log('Record data:'); store.each(function (record) { console.log(record.getData()); }); } }, { xtype : 'button', text : 'Alert Number of Records', handler : function () { alert('Data loaded, store has ' + store.getCount() + ' items'); } } ] });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
7 Jun 2012 12:12 PM #3
I've got the exact same problem as OP
I've got the exact same problem as OP
Hi,
I have the same problem as the original poster, could you elaborate on what you had to do to fix this?
My code:
Model:
Store:Code:Ext.define('App.model.User', { extend: 'Ext.data.Model', config: { fields: [ { name: 'id', type: 'int'}, { name: 'fname', }, { name: 'sname', }, { name: 'email', }, { name: 'phone', }, { name: 'network', }, { name: 'password', }, { name: 'loggedIn' }, { name: 'app_auth' }, { name: 'bango_id' } ] } });
Controller (I've tried both looping through and deleting all entries as well as using removeAll):Code:Ext.define('App.store.LocalUser', { extend: 'Ext.data.Store', config: { model: 'App.model.User', proxy : { type : 'localstorage', id : 'local-user' } } });
Local storage:Code:doLogout: function() { this.LocalUser = Ext.getStore('LocalUser'); this.LocalUser.each(function(record){ this.LocalUser.remove(record); this.LocalUser.sync(); }, this); this.LocalUser.removeAll(); this.LocalUser.sync(); this.showLogin(); },
Before .sync:
before.jpg
After .sync:
after.jpg
-
7 Jun 2012 1:11 PM #4
What version of ST are you using? After updating to 2.0.1.1, this bug was gone, and my app worked fine, so make sure your ST version is up to date.
-
18 Jun 2012 3:10 AM #5
Hi,
I had the same issue after upgrading to ST 2.0.1.1 the problem was how model id's where generated :
in my ST 2.0.0 app my model was defined :
and id where generated as int's :Code:[...] extend : "Ext.data.Model", config : { idProperty : "id", fields : [ { name : "id", type : "int " }, [...]
i had a clean id's under my controllCode:var absoluteMaxId = myStore.max("id"); var personId = (absoluteMaxId == null) ? 0 : (absoluteMaxId + 1);
in ST 2.0.1.1 had to switch model def to :
i also had to remove my own way o generating id'sCode:[...] extend : "Ext.data.Model", config : { idProperty : "id", identifier: "uuid", fields : [ { name : "id", type : "auto" }, [...]
because with my own id's ST 2.0.1.1 wouldn't remove indexes from the localstoreCode:var absoluteMaxId = myStore.max("id"); var personId = (absoluteMaxId == null) ? 0 : (absoluteMaxId + 1);
Now id's are generated with uuid's and its working ok, although i don't understand why was it changed in the new release if there were no problems (at least in my case)
-
7 Nov 2012 5:14 AM #6
I think that this issue has to be re-opened. There are many of us with the same problem and the test case that Mitchell used was not the same as the one provided by OP.
The console.log returns the correct info, but the proxy is *not* cleared, which is visible using the web inspector of the browser. The ids of the deleted items stick around and cause an error on page refresh: Uncaught TypeError: Cannot read property 'isModel' of undefined
I am experiencing this on 2.0.1.1
-
7 Nov 2012 5:40 AM #7Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 435
Give me a runnable testcase and I will test it
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
5 Apr 2013 1:18 AM #8
因为你存在旧版本的store,所以不能被识别!你可以把store全删掉以解决问题
Looks like we can't reproduce the issue or there's a problem in the test case provided.


Reply With Quote