我使用 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();