我有一個顯示的餐館列表以及餐廳的標誌列表等顯示從嵌套的JSON列表:煎茶觸摸2
視圖
Ext.define('Test.view.Contacts', {
extend: 'Ext.List',
xtype: 'contacts',
config: {
title: 'Stores',
cls: 'x-contacts',
store: 'Contacts',
itemTpl: [
'<div class="headshot" style="background-image:url(resources/images/logos/{logo});"></div>',
'{name}',
'<span>{add1}</span>'
].join('')
}
});
當您點擊餐廳我希望它顯示基於項目點擊另一個列表。
第二視圖
Ext.define('Test.view.Menu', {
extend: 'Ext.List',
xtype: 'contact-menu',
config: {
title: 'Menu',
cls: 'x-contacts',
store: 'Contacts',
itemTpl: [
'<div>{item}</div>'
].join(''),
},
});
這些模型
Ext.define('Test.model.Contact', {
extend: 'Ext.data.Model',
config: {
fields: [
'name',
'logo',
'desc',
'telephone',
'city',
'add1',
'post',
'country',
'latitude',
'longitude'
],
proxy: {
type: 'ajax',
url: 'contacts.json'
}
},
hasMany: {
model: "Test.model.Menus",
name: 'menus'
}
});
Ext.define('Test.model.Menus', {
extend: 'Ext.data.Model',
config: {
fields: [
'item'
]
},
belongsTo: "Test.model.Contact"
});
商店
Ext.define('Test.store.Contacts', {
extend: 'Ext.data.Store',
config: {
model: 'Test.model.Contact',
autoLoad: true,
//sorters: 'name',
grouper: {
groupFn: function(record) {
return record.get('name')[0];
}
},
proxy: {
type: 'ajax',
url: 'contacts.json',
reader: {
type: 'json',
root: 'stores'
}
}
}
});
的JSON
{
"stores": [{
"name": "Science Gallery",
"logo": "sciencegallery.jpg",
"desc": "Get some food",
"telephone": "016261234",
"city": "Dublin",
"add1": "Pearse Street",
"post": "2",
"country": "Ireland",
"latitude": "53.34422",
"longitude": "-6.25006",
"menu": [{
"item": "SC Sandwich"
}, {
"item": "SC Toasted Sandwich"
}, {
"item": "SC Panini"
}, {
"item": "SC Ciabatta"
}, {
"item": "SC Burrito"
}]
}, {
"name": "Spar",
"logo": "spar.jpg",
"desc": "Get some food",
"telephone": "016261234",
"city": "Dublin",
"add1": "Mayor Street",
"post": "2",
"country": "Ireland",
"latitude": "53.34422",
"longitude": "-6.25006",
"menu": [{
"item": "Spar Sandwich"
}, {
"item": "Spar Toasted Sandwich"
}, {
"item": "Spar Panini"
}, {
"item": "Spar Ciabatta"
}, {
"item": "Spar Burrito"
}]
}]
}
我想,以示對餐廳selectedbut的菜單項列表(項目,項目,項目...)當我使用嵌套列表我必須使用相同的模板,因爲以前不適合我需求的清單。目前,我獲得了適量的物品,但沒有顯示。你能幫我解決我要去哪裏的錯誤,謝謝。
感謝您的回答@rdougan,要試一試,我會確認您的答案。 – Wadester 2012-04-01 21:47:27
對不起@rdougan我試過你提供的例子,我已經得到了那麼多,但現在我想先顯示餐館列表,然後當你點擊其中一個菜單項時,它會顯示另一個菜單項目列表,你能幫助嗎?我實現這一目標。 – Wadester 2012-04-02 11:51:33
得到它排序,使用tpl的嵌套列表爲不同的節點。 – Wadester 2012-04-03 11:29:11