在 YUI Table 中访问嵌套 JSON
Accessing Nested JSON in YUI Table
在我的 YUI 应用程序中,我从 AJAX 请求
返回了以下有效的 JSON 对象
{
"content": [
{
"id": 7,
"name": "Henry Wood",
"sport": {
"sportId": 1,
"sportName": "Basketball"
}
]
}
在我的回复中,我为 table 设置了从 content
开始的数据
dataTable.set('data', data.content);
但是,在定义我的列时,我似乎无法使用点符号检索 sportName
(returns 空白)
{ key: 'name', label: 'Name'}, //returns Henry Wood
{ key: 'sport.sportName', label: 'Supply Chain', //doesn't work
关于如何访问此嵌套 属性 的任何想法?
像这样对列定义使用格式化程序选项
formatter: function (o) {
return o.data.sport.sportName;
}
列定义:
var cols = [{
key: 'name',
label: 'Name'
}, {
label: 'Supply Chain',
formatter: function (o) {
return o.data.sport.sportName;
}
}],
在我的 YUI 应用程序中,我从 AJAX 请求
返回了以下有效的 JSON 对象{
"content": [
{
"id": 7,
"name": "Henry Wood",
"sport": {
"sportId": 1,
"sportName": "Basketball"
}
]
}
在我的回复中,我为 table 设置了从 content
dataTable.set('data', data.content);
但是,在定义我的列时,我似乎无法使用点符号检索 sportName
(returns 空白)
{ key: 'name', label: 'Name'}, //returns Henry Wood
{ key: 'sport.sportName', label: 'Supply Chain', //doesn't work
关于如何访问此嵌套 属性 的任何想法?
像这样对列定义使用格式化程序选项
formatter: function (o) {
return o.data.sport.sportName;
}
列定义:
var cols = [{
key: 'name',
label: 'Name'
}, {
label: 'Supply Chain',
formatter: function (o) {
return o.data.sport.sportName;
}
}],