繁体   English   中英

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

[英]Kendo Grid renders properly but does not display json data

我最近在网格上度过了一段艰难的时光,主要是让它们显示从Web服务(已在VS2013和JSONLint中检查过)获取的格式正确的JSON数据,如果第二眼可以看一下在我的解决方案中,告诉我缺少什么? 我要香蕉!

函数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" }
                    ]
                });

    }
});   

}

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

可以通过添加一个json选项来减轻这种情况:

1:变更

services.AddMvc();

服务

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

要么

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

最终弄清楚了,“ ProductData”字段-尽管采用了完美的JSON格式-仍需要在数据源配置中解析为JSON,就像这样,...

数据:JSON.parse(ProductData)

暂无
暂无

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

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