如何将 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.
推荐答案
在响应中,您已将 container
定义为 array
但不确定它是否可能重复.据我了解,实际数据是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屋!