每次刷新页面时,本地存储中的数据都会被刷新

时间:2012-12-28 10:31:45

标签: sencha-touch-2 local-storage

使用sencha touch 2并使用本地存储, 但是一旦我刷新页面,数据就会被刷新,请你告诉我什么是错的,这里是我店的代码并插入删除功能

Ext.define("OfferDrive.store.CategoryStore", {
    extend: "Ext.data.Store",
    requires: "Ext.data.proxy.LocalStorage",
    config: {
        model: "OfferDrive.model.StoreCategories",
        proxy: {
            type: 'localstorage',
            id: 'favorite-category-store'
        }
    }
});

这里是视图中添加或插入记录的代码

            var favCategoriesStore = Ext.getStore('CategoryStore');

            for (var i=0; i< categoryList.config.store.data.items.length; i++)
            { 
                if(categoryList.config.store.data.items[i].data.CheckUrl.indexOf("Golden") != -1){
                    var record = favCategoriesStore.findRecord('Id', categoryList.config.store.data.items[i].data.Id)
                    if (null == record){
                        //insert
                        var newFavorite = Ext.create("OfferDrive.model.StoreCategories", {
                            Id: categoryList.config.store.data.items[i].data.Id,
                            Name: categoryList.config.store.data.items[i].data.Name
                        });
                        favCategoriesStore.add(newFavorite);                                
                    }
                }else{
                    var record = favCategoriesStore.findRecord('Id', categoryList.config.store.data.items[i].data.Id)
                    if (null != record){
                        //remove
                        favCategoriesStore.remove(record);
                    }
                }
            }

            favCategoriesStore.sync();

0 个答案:

没有答案