gpt4 book ai didi

json - 如何在 EXTJS 4 网格中显示嵌套的 Json 数据?

转载 作者:行者123 更新时间:2023-12-04 00:57:17 25 4
gpt4 key购买 nike

我正在使用 ExtJS 4.0,我想在网格中显示嵌套的 JSON 数据。为此,我使用 Ext.data.reader.Reader docs, "Loading Nested Data" 中给出的示例.这很好也很简单,但现在我想在网格中显示这些数据。如何设置 dataIndex ?

这是我的示例模型和商店:

Ext.define("data", {
extend: 'Ext.data.Model',
fields: ['year', 'state'],
hasMany: {
model: 'record',
name: 'record'
},
proxy: {
type: 'rest',
url: 'Column.json.php',
reader: {
type: 'json',
root: 'data'
}
}
});

Ext.define("record", {
extend: 'Ext.data.Model',
fields: ['id', 'autorization', 'expendture'],
belongsTo: 'User'
});
var store1 = new Ext.data.Store({
model: "data"
});

还有我的 JSON:
{
"data": [{
"year": "2010",
"state": "MP",
"record": [{
"id": "auth",
"autorization": "9.201"
}, {
"id": "exp",
"expendture": "1.250"
}]
}]
}

我要阅读 autorizationexpendtureid

最佳答案

您必须使用 mapping 在模型/记录级别执行此操作。 confg 在字段中,所以你会做这样的事情:

Ext.define("record", {
extend: 'Ext.data.Model',
fields: [
'id',
{name: 'autorization', mapping: 'record[0].autorization'},
{name: 'expendture', mapping: 'record[1].expendture'}
],
belongsTo: 'User'
});

值得注意的是,在 Sencha Forums 上提问可能会更快。 .

关于json - 如何在 EXTJS 4 网格中显示嵌套的 Json 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6265641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com