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