如何使用嵌套的
JSON填充Kendo UI网格.
我的意思是我的JSON就像
var myJson:
[{"oneType":[
{"id":1,"name":"John Doe"},{"id":2,"name":"Don Joeh"}
]},{"othertype":"working"},{"otherstuff":"xyz"}]
}];
我希望Kendo UI Grid的列为Id,Name,OtherType和OtherStuff.
提前致谢.!
解决方法
对于复杂的JSON结构,您可以使用
schema.parse
var grid = $("#grid").kendoGrid({
dataSource : {
data : [
{
"oneType": [
{"id": 1,"name": "John Doe"},{"id": 2,"name": "Don Joeh"}
]
},{"othertype": "working"},{"otherstuff": "xyz"}
],pageSize: 10,schema : {
parse : function(d) {
for (var i = 0; i < d.length; i++) {
if (d[i].oneType) {
return d[i].oneType;
}
}
return [];
}
}
}
}).data("kendoGrid");
如果您稍微将JSON更改为:
{
"oneType" : [
{"id": 1,"name": "Don Joeh"}
],"othertype" : "working","otherstuff": "xyz"
}
然后你可以使用:
var grid = $("#grid").kendoGrid({
dataSource: {
data : {
"oneType" : [
{"id": 1,"name": "Don Joeh"}
],"otherstuff": "xyz"
},schema : {
data: "oneType"
}
}
}).data("kendoGrid");