1
我有一個名爲data.json一個JSON文件,它包含以下JSON:如何爲此數據創建模型/商店?
{
"lists": [
{
"id":100,
"title":"Grocery",
"description":"Bryce & Madi",
"items": [
{
"name":"Milk",
"quantity":"2 Gallons",
"checked":false
},
{
"name":"Sugar",
"quantity":"2 Cups",
"checked":true
}
]
},
{
"id":200,
"title":"Christmas",
"description":"Our Christmas List",
"items": [
{
"name":"Shaver",
"quantity":"1",
"checked":false
},
{
"name":"Football",
"quantity":"1",
"checked":true
}
]
}
]
}
我試圖創建一個模型/存儲這個數據讓我看到第一隻主清單頁面,然後他們可以單擊一個列表,並將它們帶到一個頁面,該列表將該列表中的items
顯示爲一個列表。
任何人都可以指向正確的方向嗎?我一直在圍繞這個結構纏繞我的頭。如果有幫助,這是我有:
App.models.Lists = Ext.regModel("App.models.Lists", {
hasMany: { model: App.models.List, name: 'list' },
fields: [
{ name: "id", type: "int" },
{ name: "title", type: "string" },
{ name: "description", type: "string" },
{ name: "items", type: "auto" }
]
});
App.stores.Lists = new Ext.data.Store({
model: "App.models.Lists",
proxy: {
type: 'ajax',
url: 'data.json',
id: 'AppLocalStore',
reader: {
type: 'json',
root: 'lists'
}
},
listeners: {
'load': function(store, records, options) {
console.log(records);
}
}
});