简体   繁体   English

修改JSON并在Kendo UI网格中显示

[英]Modify JSON and display in Kendo UI Grid

Given this JSON: 鉴于此JSON:

{
"Header": {
    "NewNetworkServiceProvider": "NewNetworkServiceProvidera9ae97fe-e59a-4678-91ea-5a03c7d0f5cc",
    "PurchaseOrderNumber": "PurchaseOrderNumberdf932a47-1476-4a78-a9d0-de538ed8306b",
    "ConfirmedVersionString": "ConfirmedVersionString12e9d37c-f8dd-4251-bc55-7c83732b5629"
    }
}

} }

I would like to turn it into: 我想把它变成:

[
  { "label": "NewNetworkerviceProvider", "value": "NewNetworkServiceProvider87cc6600-49c5-46fa-9fe7-d6f614645edb"},
  { "label": "PurchaseOrderNumber", "value": "PurchaseOrderNumber85475a1e-f22d-46f0-b437-9528b7564ab1" },
  { "label": "ConfirmedVersionString", "value": "VersionString2fa72562-dec5-4edd-9ba3-e2e2c563acb6" }
];

Then I can make that a data source in the Kendo UI Grid. 然后,我可以在Kendo UI网格中将其作为数据源。

I just need a push in the right direction to either transform that data into the format I need or is there a move advanced method to apply a schema template that will dynamically display the data in the way I need it to. 我只需要按正确的方向进行操作即可将数据转换为所需的格式,或者是否可以使用高级方法来应用架构模板,该模板将按照需要的方式动态显示数据。

At the moment using that test data I can display it in the grid and it's awesome. 目前,使用该测试数据,我可以将其显示在网格中,而且很棒。

You can iterate the property and use hasOwnProperty 您可以迭代该属性并使用hasOwnProperty

var json = {
"Header": {
    "NewNetworkServiceProvider": "NewNetworkServiceProvidera9ae97fe-e59a-    4678-91ea-5a03c7d0f5cc",
    "PurchaseOrderNumber": "PurchaseOrderNumberdf932a47-1476-4a78-a9d0-    de538ed8306b",
    "ConfirmedVersionString": "ConfirmedVersionString12e9d37c-f8dd-4251-bc55-7c83732b5629"
    }
}

var result = []

for (var property in json.Header)
{
    if (json.Header.hasOwnProperty(property)) {
                var obj = {label:"",value:""}
                obj.label = property ; 
                obj.value = json.Header[property];
                result.push(obj);
            }
}

you can stringify the js object by using JSON.stringify 您可以使用JSON.stringify来对js对象进行字符串化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM