如何使用嵌套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
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": "John Doe"}, {"id": 2, "name": "Don Joeh"} ], "othertype" : "working", "otherstuff": "xyz" }
那么您可以使用:
var grid = $("#grid").kendoGrid({ dataSource: { data : { "oneType" : [ {"id": 1, "name": "John Doe"}, {"id": 2, "name": "Don Joeh"} ], "othertype" : "working", "otherstuff": "xyz" }, pageSize: 10, schema : { data: "oneType" } } }).data("kendoGrid");