Doc*_*ard 5 json extjs extjs4 extjs4.1 extjs6
我有一个这样的网格存储。
var gridStore = Ext.create('Ext.data.Store',{
proxy : {
type : 'ajax',
actionMethods : {
read : 'POST'
},
url : 'getECIAgentWrapperJobs.do',
reader : {
type : 'json',
rootProperty : 'rows',
totalProperty : 'results'
}
},
pageSize : 3,
autoLoad : {start: 0, limit: 3}
});
Run Code Online (Sandbox Code Playgroud)
显然,它向URL发出AJAX请求。我为此商店得到的JSON响应如下所示:
{
"results":2,
"rows":[
{
"pkTable1":1,
"name":"Rick",
"eciAgentJob":{
"pkTable2":11,
"name":"Play Local Ar",
},
}
],
"msg":null,
"success":true,
}
Run Code Online (Sandbox Code Playgroud)
现在这是我的网格的外观:
var mappedEciAgentJobsGrids = Ext.create('Ext.grid.Panel',{
store : gridStore,
columns : [
{
dataIndex : 'pkTable1',
header : 'Pk of table 1'
},
{
dataIndex : 'name',
header : 'Name'
},
{
dataIndex : 'eciAgentJob.pkTable2',
header : 'Pk of Table 2'
}
]
});
Run Code Online (Sandbox Code Playgroud)
现在在我的用户界面中,前两列(分别具有dataIndex:pkTable2和name)可以很好地加载。但是对于第三个,它不是。我知道这是因为我已经使用dataIndex作为'eciAgentJob.pkTable2'。但是,当我们像我一样获得响应时,将数据加载到列中的方式是什么(其中eciAgentJob是原始JSON中的对象)。请帮忙。
编辑:由于某些其他用例原因,我不想使用渲染器。
小智 2
在模型中定义一个新字段并映射到所需字段。在转换函数中从记录中选择任何值。
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'name', type: 'string ' },
{
name: 'columnName',
convert: function (value, record) {
return "return what ever you want"
}
}
]
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
83 次 |
| 最近记录: |