从Sencha Touch 2中的Localstorage代理中删除记录

时间:2012-11-06 22:08:44

标签: sencha-touch-2

所以我的问题是这个。我可以第一次从localstorage代理中删除记录。但是,如果我再次这样做,它会给我一个错误,即Store中的所有内容都是未定义的,就像它不再存在一样。

 onTapRemoveKegelReminder: function(button) {
    console.log(button.getData());
    //Find and delete the button and the record
    var store = Ext.getStore('KegelReminders');
    store.load();
    store.filter('button_id', button.getData());
    var record = store.first();


    console.log(record);
    console.log(button.getData());
    console.log('Remove count'+ store.getCount());


    if (typeof record !== 'undefined'||record!=null ) {
        store.remove(record);
        store.sync();


        console.log('removed record correctly')
        this.trainingCount--;
        var rmButton = this.getKegelExercises().down('#container-' + button.getData());
        this.getKegelExercises().remove(rmButton);

    }

但是,如果我重新启动我的应用程序,然后再次删除它可以正常工作。我不能在不必重新启动应用程序的情况下多次删除。

1 个答案:

答案 0 :(得分:3)

如果其他人发现这种情况,从商店中删除记录只会将其从商店实例中删除,而不是从存储机制中删除(例如,localstorage)。如果你想这样做,你必须在模型对象上使用erase method

store.remove(record); // may not even be necessary
record.erase();
store.sync();