我在與煎茶觸摸和localStorage的幾個問題...煎茶觸摸 - localStorage的問題
1)我能數據保存到本地存儲,直到我刷新頁面,它的偉大工程。在那之後,我仍然可以訪問數據,看起來可以做出更改,甚至可以添加新條目。但只要刷新頁面,我的所有更新都將消失。任何新添加的內容都可以,但是原始條目的更新不會被保存(希望這是有道理的)。基本上,我可以創建一個條目並更新它,直到我刷新頁面。此時它不會再保存到本地存儲。新的條目總是可以很好地保存。 2)當我刪除所有條目,然後刷新頁面時,我在控制檯中得到這個錯誤:「未捕獲的TypeError:無法讀取'null'屬性'id'。它看起來像試圖加載一些東西,即使沒有東西。我不知道爲什麼它會在這種情況下拋出一個錯誤,而不是當頁面最初被加載時,因爲它應該是同樣的事情嗎?
型號:
Ext.regModel('inventoryItem', {
idProperty: 'id',
fields: [
{ name: 'id', type: 'int' },
{ name: 'date', type: 'date', dateFormat: 'c' },
{ name: 'title', type: 'string' },
{ name: 'quantity', type: 'int' },
{ name: 'size', type: 'int' },
{ name: 'cost', type: 'double' },
{ name: 'startDate', type: 'date' },
{ name: 'endDate', type: 'date' },
{ name: 'dailyAvgCost', type: 'string' },
{ name: 'dailyAvgSize', type: 'string' }
]
});
商店:
Ext.regStore('inventoryItemsStore', {
model: 'inventoryItem',
sorters: [{
property: 'id',
direction: 'DESC'
}],
proxy: {
type: 'localstorage',
id: 'inventory-app-store'
},
getGroupString: function (record) {
return '';
}
});
處理程序:
{
var currentinventoryItem = CostsApp.views.inventoryEditor.getRecord();
CostsApp.views.inventoryEditor.updateRecord(currentinventoryItem);
var inventoryStore = CostsApp.views.inventoryList.getStore();
if (null == inventoryStore.findRecord('id', currentinventoryItem.data.id))
{
inventoryStore.add(currentinventoryItem);
}
inventoryStore.sync();
inventoryStore.sort([{ property: 'date', direction: 'DESC'}]);
CostsApp.views.inventoryList.refresh();
}
任何人都可以指出someth很明顯,我做錯了?
CostsApp.views.inventoryEditor.updateRecord(currentinventoryItem);做?這聽起來像你的模型不知道他們已經出於某種原因被編輯。 – 2012-02-17 06:30:21