问题
I use a web api to send data to display in Kendo UI grid. my web api return a nested json. As follows:
{
"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"
}
]
}
After that, I will try to display the data in the following way :
columns: [
{ field: "OperationalRisks.LocationCode", title: "#" },
{ field: "OperationalRisks.RegisterDate", title: "#" }
]
And:
schema: {
model: {
fields: {
"OperationalRisks.LocationCode": { type: "number" },
"OperationalRisks.RegisterDate": { type: "number" }
}
}
}
But the data isn't bind to grid
回答1:
My problem was easily solved and I would like to share this with you first of all you should define:
var json_data;
and after that:
$("#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" }
}
}
}
来源:https://stackoverflow.com/questions/62971752/how-can-i-mapping-nested-json-to-kendo-ui-grid