最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Sencha Touch localstore proxy not removing indexes after records deleted - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Sep 3, 2012 at 12:51 aKzenT 7,9152 gold badges37 silver badges66 bronze badges asked Jun 2, 2012 at 14:39 Michael McClenaghanMichael McClenaghan 6591 gold badge5 silver badges11 bronze badges 2
  • Here is a screenshot of the data store before the remove method is called: i.imgur./HmOtT.png And here is one after: i.imgur./VEmeq.png Note the Id still stays in the store's list, which gives me the undefined error when the page is refreshed – Michael McClenaghan Commented Jun 2, 2012 at 14:41
  • can you please provide structure of your model – Parv Sharma Commented Sep 3, 2012 at 13:05
Add a ment  | 

2 Answers 2

Reset to default 5 +50

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./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

发布评论

评论列表(0)

  1. 暂无评论