Javascript Kendo Grid "Cannot read property ' length' of null"错误

标签 javascript kendo-grid

我有一个可扩展的剑道网格,它从按不同实体分组的两个存储过程返回数据。但是,它仅返回三个实体之一的有效负载列中的数据。在开发人员控制台中调试时,它返回“无法读取 null 的属性‘长度’”。我已经评论了似乎导致错误的代码行。我不确定为什么它只会对三个实体值之一执行此操作,但想知道是否有人提出修复建议,因为我是初学者。请告诉我,谢谢!

function InitiateGrid(e) {        
        var grid = e.detailRow.find(".entityDetail").kendoGrid({
            dataSource: {
                type: "json",
                transport: {
                    read: function (option) {
                        $.ajax({
                            contentType: "json",
                            url: "/Test.svc/json/GetDetail",
                            success: function (result) {
                                option.success(result.Response); //error happening within this line of code
                            },
                            error: function (result) {
                                option.error(result.Response);
                            },
                            data: {
                                entityId: function () { return $("#txtEntityId").val(); },
                                entityTypeName: function () { return $("#txtEntityType").val(); }
                            }
                        });
                    }
                },
                schema: {
                    model: {
                        fields: {
                            Number: { type: "string", editable: false, nullable: true },
                            Id: { type: "string", editable: false },
                        }
                    }
                },
            },
            scrollable: true,
            sortable: true,
            pageable: false,
            selectable: "row",
            columns: [
                {
                    filterable: false,
                    title: "Number",
                    field: "Number",
                    width: 25,
                },
                {
                    filterable: false,
                    field: "Id",
                    title: "Id",
                    width: 25,
                }
            ]
        });
    }

最佳答案

您不需要在 Kendo Data Source 中另一个 Ajax 请求.

transport: {
   read: {
      url: "/Test.svc/json/GetDetail",
      type: "get",
      dataType: "json",
      data: {
         entityId: function () { return $("#txtEntityId").val(); },
         entityTypeName: function () { return $("#txtEntityType").val(); }
      }
   },

关于Javascript Kendo Grid "Cannot read property ' length' of null"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45699498/

相关文章:

javascript - 如何在剑道网格中只对一个字段进行分组?

javascript - 无法在 Jquery 中获取复选框值?

java - 通过 Java ScriptEngine 在 JavaScript 中使用 jar

JavaScript 打印被 Chrome 阻止,解决方法?

html - 文本溢出 : ellipsis show weird characters on IE11

javascript - 在 Kendo Grid 中动态生成列时未捕获语法错误 : Unexpected number,

kendo-ui - Kendo UI Grid 无边框请求

javascript - 在图像加载时开始幻灯片放映

javascript - 拖放和可排序 jquery 插件之间的冲突

angular - 带有复选框列的 Kendo Angular 2 网格