如何将JSON子数组绑定到Kendo网格 [英] How to bind JSON child array to Kendo grid
问题描述
假设我有以下JSON数据,这是HTTP服务调用的响应数据...
Let´s say I have the following JSON data, which is the response data of an HTTP service call...
{
[ "container" : [
{
"category" : "default",
"items" : [
{ "name" : "item-1" },
{ "name" : "item-2" }
]
} ]
]
}
我想将 items
数组绑定到Kendo UI Grid,所以我定义了以下内容数据源......
I want to bind the items
array to the Kendo UI Grid, so I defined the following data source...
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "http://...",
dataType: "jsonp",
data: {
Accept: "application/json"
}
}
},
schema: {
model: ???
}
});
我绝对不知道如何定义模型模式,因为我找不到任何关于文档中的特定绑定方案。
I´ve absolutely no clue how to define the model schema because I couldn´t find any information on that particular binding scenario in the documentation.
推荐答案
在响应中,您已定义容器
作为数组
但不确定是否可能重复。据我所知,实际数据是 items
。正确?如果是这样,这是最小的DataSource定义。
In the response, you have defined container
as an array
but not sure if it might repeat. As far as I understand the actual data is items
. Correct? If so, this is the minimum DataSource definition.
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url : "http://...",
dataType: "json",
data: {
Accept: "application/json"
}
}
},
pageSize : 10,
schema : {
data: "container[0].items"
}
});
注意:您显示的响应看起来不像JSONP但是JSON。这就是我将 dataType
设置为JSON的原因。
NOTE: The response that you show doesn't look like a JSONP but a JSON. That's why I'm setting dataType
as JSON.
这篇关于如何将JSON子数组绑定到Kendo网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!