我正在尝试循环嵌套的 json 数组以显示网格单元中的值(使用 extjs 6.0)。
这是 View 中的列:
{
header: 'Participants',
dataIndex: 'participants'
},
型号:
Ext.define('App.model.Event', {
extend: 'Ext.data.Model',
fields: [
{ name: 'eventTypeName', type: 'auto', mapping: 'eventType.eventType' },
// this only grabs the first object in the list....how to grab all?
{ name: 'participants', type: 'auto', mapping: 'participants[0].participantName' },
]
});
还有 json:
{
"_embedded" : {
"events" : [ {
"participants" : [ {
"participantId" : 1,
"participantName" : "name1"
}, {
"participantId" : 2,
"participantName" : "name2"
}, {
"participantId" : 3,
"participantName" : "name3"
} ],
}
}
}
网格中的行是事件,每个事件行将有多个我想在单元格中显示的参与者。如何在一个单元格中显示所有参与者的姓名?
我已经使用 hasMany 方法尝试了与本文类似的方法,但无济于事:https://www.sencha.com/forum/showthread.php?205509-Displaying-a-hasMany-model-relationship-in-a-Grid&p=822648&viewfull=1#post822648
最佳答案
如果你想在单元格中显示特殊内容,那么你需要实现 renderer 。在渲染器函数中,您将迭代当前行的参与者,根据您希望该单元格的外观构建并返回 HTML 字符串。
关于javascript - 如何在 extjs 网格单元中显示嵌套数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32128148/