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"
Here is the code for the store:
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
onDeleteHomeworkCommand: function () {
var dataEditor = this.getDataEditor();
var currentData = dataEditor.getRecord();
var dataStore = Ext.getStore("Data");
dataStore.remove(currentData);
dataStore.sync();
this.activateDataList();
},
Edit:
Here is a screenshot of the data store before the remove method is called:
And here is one after:
Note the Id still stays in the store's list, which gives me the undefined error when the page is refreshed.
The problem is that the local store proxy does not remove the ID from its internal ID list when you remove the record. You can solve this if you explicitly destroy the record in the proxy with destroy().
this is kind of a known issue with the localstorage
proxy and stores
in sencha touch and happens because by defualt sencha takes the ids to be int and hence the problem arises when they are not. i found out a solution to this problem in one of the sencha forums and it worked for me
this is a link to that thread http://www.sencha.com/forum/showthread.php?151741-remove-record-from-localstorage
and the solution is to edit a line of code in the source of sencha touch and here that goes
And now I fixed the problem with the ids not being clean up.
There is a use of getID which returns an Int but the list of ids is an array of strings
//This line doesn't work circa 32196
Ext.Array.remove(newIds, records[i].getId());
//Replace it with this one works fine.
Ext.Array.remove(ids, records[i].getId().toString());
This might be because my model uses 'id' of type 'int', because that's what I thought the doc suggests but I could be wrong.. Have a look
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With