Kendo Grid正确渲染但不显示json数据

时间:2014-11-19 19:20:39

标签: ajax json kendo-ui grid

我最近在使用网格时遇到了困难,主要是让他们显示正在从Web服务中获取的格式正确的JSON数据(已在VS2013和JSONLint中检查过),如果第二组眼睛可以请看看我的解决方案并告诉我什么缺乏?我要去香蕉!

函数SetTelerikGrid(){

// prepare the data object and consume data from web service,...
$.ajax({
    type: "GET",
    async: false,
    url: "http://localhost:38312/SDMSService.svc/GetProductPositionsByLocation/0544",
    datatype: "json",
    success: function (ProductData, textStatus, jqXHR) {

        // populate kendo location grid by data from successful ajax call,...
        $("#LocationProductsGrid").kendoGrid({
                    dataSource: {
                        data: ProductData, // solution here was: **JSON.parse(LocationData)**
                        schema: {
                            model: {                                    
                                fields: {
                                    Date: { type: "string" },
                                    ProductCode: { type: "string" },
                                    StoreNum: { type: "string" },                                        
                                    ProductQty: { type: "int" }
                                }
                            }
                        },
                        pageSize: 20
                    },
                    height: 550,
                    scrollable: true,
                    sortable: true,
                    filterable: true,
                    pageable: {
                        input: true,
                        numeric: false
                    },
                    columns: [
                        { field: "Date", title: "Date", width: "130px" },
                        { field: "ProductCode", title: "Product Code", width: "130px" },
                        { field: "StoreNum", title: "Store Number", width: "130px" },                            
                        { field: "ProductQty", title: "Product Qty", width: "130px" }
                    ]
                });

    }
});   

}

2 个答案:

答案 0 :(得分:4)

ASP.NET Core 发生了重大变化,与JSON serializer

的方式有关

作品 你可以通过添加像这样的json选项来缓解这种情况:

<强> 1 变化

services.AddMvc();

服务

.AddMvc()
    .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());

OR

<强> 2

public IActionResult Read()
{
  // Override serializer settings per-action
  return Json(
     MyModel,
     new JsonSerializerSettings { ContractResolver = new DefaultContractResolver() }
  );
}

参考: http://www.telerik.com/forums/using-2016-2-630-preview---data-not-displayed#qlHR6zhqhkqLZWuHfdUDpA

https://github.com/telerik/kendo-ui-core/issues/1856#issuecomment-229874309

https://github.com/telerik/kendo-ui-core/issues/1856#issuecomment-230450923

答案 1 :(得分:0)

最后想通了,'ProductData'字段 - 尽管是完美的JSON格式 - 仍然需要在数据源配置中解析为JSON,就像这样,......

数据:JSON.parse(ProductData)