如何从json文件中读取kendo网格列

时间:2015-01-29 06:17:53

标签: json kendo-ui kendo-grid

我有一个kendo网格,它从远程json文件中读取数据。我希望网格列也应该从同一个json文件中读取,这样我就不必一次又一次地更改客户端代码。无论json文件中是什么,它都应该能够在客户端没有任何硬编码的情况下呈现相同的数据。我的json文件看起来像

{ "data":[
    {"_type":"ProductDetails:#NWProducts","Discount":0,"OrderId":10248,"ProductId":11,"UnitPrice":14.0000,"quanity":12},{"_type":"ProductDetails:#NWProducts","Discount":0,"OrderId":10248,"ProductId":42,"UnitPrice":9.8000,"quanity":10},{"_type":"ProductDetails:#NWProducts","Discount":0,"OrderId":10248,"ProductId":72,"UnitPrice":34.8000,"quanity":5},{"_type":"ProductDetails:#NWProducts","Discount":0,"OrderId":10249,"ProductId":14,"UnitPrice":18.6000,"quanity":9}],
"columns":[
{"field":"_type","title":"Type"},{"field":"Discount","title":"Discount($)"},{"field":"OrderId","title":"Order ID"},{"field":"ProductId","title":"Product ID"},{"field":"UnitPrice","title":"Unit Price"},{"field":"quanity","title":"Quanity"}]
}

HTML代码如下

<div id="grid"></div>

JS代码在

之下
 $("#grid").kendoGrid({
    title: { text: "Stats" },
    sortable: false,
    pageable: {
        pageSizes: true,
        buttonCount: 5
    },
    columnMenu: true,
    dataSource: {
        transport: {
            read: {
                url: "............/demo.json",
                dataType: "json"
            }
        },
        schema: {
            data: "data"
        }
    },
    columns: {
     //What should be done here.
 }
});

我尝试了相同的传输读取模式方式来获取列数据,但它不起作用。如果我将相同的列json数据存储在变量中并将该变量替换为列,那么它就可以工作。有没有办法将json数据列存储在json文件的变量中。实现此行为的最佳方法是什么。任何帮助,将不胜感激。 在此先感谢。

0 个答案:

没有答案