我是 sencha touch2 的新手,在列表的单独行中显示嵌套的 json 数据时遇到问题。这是我的 Json 的样子:
[
{
"work": {
"agent": {
"activeFlag": "false",
"shiftId": "0",
"id": "0",
"deleteFlag": "false"
},
"id": "124",
"status": "Unassigned",
"assignment": {
"pnr": {
"locator": "ABCDEF",
"connectTime": "0",
"id": "0"
},
"id": "123",
"alerts": "Delay",
"customers": [
{
"lastName": "XYZ",
"firstName": "MNO"
},
{
"lastName": "PQR",
"firstName": "STU "
}
]
}
}
},
{
"work": {
"agent": {
"activeFlag": "false",
"shiftId": "0",
"id": "0",
"deleteFlag": "false"
},
"id": "124",
"status": "Unassigned",
"assignment": {
"pnr": {
"locator": "ABCDEF",
"connectTime": "0",
"id": "0"
},
"id": "123",
"alerts": "Delay",
"customers": [
{
"lastName": "ANY",
"firstName": "KLJ"
},
{
"lastName": "CHE",
"firstName": "MAK"
}
]
}
}
}
]
像这样,我有 30 个“工作”对象,在 1 个“工作”中,我有 1 个“客户”数组,里面有多个客户
我想在列表中的单独行中显示“客户”,但能够在一行中显示单个“工作”的所有客户。
Output should be:
---------------
delay
First Name: MNO
---------------
delay
First Name: STU
---------------
delay
First Name: KLJ
---------------
delay
First Name: MAK
---------------
这是模型。模型列表.js:
Ext.define('CustomList.model.ModelList', {
extend: 'Ext.data.Model',
xtype:'modelList',
requires:['CustomList.model.Customers'],
config: {
fields:['work'],
proxy:{
type:'ajax',
url:'http://localhost:9091/CustomListJson/app/store/sample.json',
reader:{
type:'json'
}
},
hasMany:{model:'CustomList.model.Customers',
name:'customers'}
}
});
客户.js:
Ext.define('CustomList.model.Customers', {
extend: 'Ext.data.Model',
config: {
fields: [
'firstName','lastName'
],
belongsTo: "CustomList.model.ModelList"
}
});
这是我的 ShowList.js:
Ext.define('CustomList.view.ShowList',{
extend:'Ext.Panel',
xtype:'showList',
config:{
layout:'fit',
styleHtmlContent:'true',
styleHtmlCls:'showListCls',
items:[
{
xtype:'list',
id: 'listitems',
store:'StoreList',
itemTpl:[ '{work.assignment.alerts}<br>',
'<tpl for="work.assignment.customers">',
'firstName: {firstName}<br>',
'</tpl>'
]
// am able get the below values in list
// itemTpl:'{work.assignment.alerts}'
// itemTpl:'{work.assignment.pnr.locator}'
// itemTpl:'{work.agent.activeFlag}'
// itemTpl: '<b>{firstName} {lastName} </b><br>'+'pnr: '+ '{locator} <br>' +
// 'Alerts: '+'{alerts}' +'status: '+'{status} '
}]
}
});
这是我的 StoreList.js:
Ext.define('CustomList.store.StoreList', {
extend:'Ext.data.Store',
requires:['Ext.data.reader.Json'],
config:{
model:'CustomList.model.ModelList',
autoLoad:'true'
}
});
谁能帮帮我吗。谢谢。