【问题标题】:Kendo Grid renders properly but does not display json dataKendo Grid 正确渲染但不显示 json 数据
【发布时间】:2014-11-19 19:20:38
【问题描述】:

我最近在使用网格时遇到了困难,主要是让它们显示从 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" }
                    ]
                });

    }
});   

}

【问题讨论】:

    标签: ajax json kendo-ui grid


    【解决方案1】:

    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

    【讨论】:

      【解决方案2】:

      终于弄明白了,'ProductData' 字段——虽然是完美的 JSON 格式——仍然需要在数据源配置中解析为 JSON,就像这样,...

      数据:JSON.parse(ProductData)

      【讨论】:

      猜你喜欢
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多