如何使用嵌套的Json填充Kendo UI网格? [英] How can I use nested Json to populate Kendo UI grid?

查看:146
本文介绍了如何使用嵌套的Json填充Kendo UI网格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用嵌套的JSON填充Kendo UI网格。

How can I populate Kendo UI grid with nested JSON.

我的意思是我的JSON就像

I mean my JSON is like

var myJson:
    [{"oneType":[
        {"id":1,"name":"John Doe"},
        {"id":2,"name":"Don Joeh"}
    ]},
    {"othertype":"working"},
    {"otherstuff":"xyz"}]
}];

我希望Kendo UI Grid的列为Id,Name,OtherType和OtherStuff。

and I want Kendo UI Grid with columns as Id, Name, OtherType and OtherStuff.

提前致谢。

推荐答案

对于复杂的JSON结构,您可以使用< a href =http://docs.kendoui.c​​om/api/framework/datasource#configuration-schema.parse> schema.parse

For complex JSON structures, you might use 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略微更改为:

If you slightly change your JSON to:

{
    "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");

这篇关于如何使用嵌套的Json填充Kendo UI网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆