如何将嵌套的 Json 映射到 Kendo UI 网格?

How can I mapping nested Json to Kendo UI grid?

我使用网络 api 发送数据以显示在 Kendo UI 网格中。我的网站 api return 嵌套 json。 如下:

{
"SearchRequest": {
        "Term": null,
        "SortDirection": "Desc",
        "Total": 0,
        "PageIndex": 1,
        "PageSize": 10,
        "CurrentSort": null
    },
    "OperationalRisks": [
        {
            "LocationCode": 224.0,
            "RegisterDate": "1/01/01"
        },
        {
            "LocationCode": 211.0,
            "RegisterDate": "1/01/01"
        }
 ]
}

之后,我会尝试用以下方式显示数据:

columns: [
                    { field: "OperationalRisks.LocationCode", title: "#" },
                    { field: "OperationalRisks.RegisterDate", title: "#" }
                ]

并且:

schema: {
                    model: {
                        fields: {
                            "OperationalRisks.LocationCode": { type: "number" }, 
                            "OperationalRisks.RegisterDate": { type: "number" }
                        }
                    }
                }

但是数据没有绑定到网格

我的问题很容易解决,我想与您分享 首先你应该定义:

var json_data;

之后:

$("#grid").kendoGrid{{
datasource:{
type:"json",
data:json_data.OperationalRisks,
.
.
.

columns: [
           { field: "LocationCode", title: "#" },
           { field: "RegisterDate", title: "#" }
         ],
.
.
.
schema: {
                    model: {
                        fields: {
                            "LocationCode": { type: "number" }, 
                            "RegisterDate": { type: "number" }
                        }
                    }
                }