简体   繁体   English

无法使用 customdropdown 读取未定义的剑道 ui js 网格的属性“数据”

[英]Cannot read property 'data' of undefined kendo ui js grid with customdropdown

Here is my js code:这是我的js代码:

$(document).ready(function () {
    $("#grid").kendoGrid({
        dataSource: {
            transport: {
                read: {
                    url: '/Discount/Get',
                    dataType: "json",
                },
                update: {
                    url: '/Discount/Update',
                    dataType: "json",
                    type: "POST"
                },
                destroy: {
                    url: '/Discount/Delete',
                    dataType: "json",
                    type: "POST"
                },
                create: {
                    url: '/Discount/Add',
                    dataType: "json",
                    type: "POST"
                },
                parameterMap: function (options, operation) {
                    if (operation == "update") {
                        return JSON.stringify(options);
                    }
                    if (operation == "create") {
                        return options;
                    }
                    if (operation == "destroy") {
                        return JSON.stringify(options);
                    }
                }
            },
            schema: {
                model: {
                    id: "Id",
                    fields: {
                        Id: { type: "number" },
                        TopItemName: { type: "string" },
                        DiscountValue: { type: "number" },
                    }
                }
            }
        },
        toolbar: ["create", "save", "cancel"],
        height: 400,
        pageable: true,
        columns: [
        {
            field: "TopItemName",
            editor: topItemDropDown,
            template: "#=TopItemName#"
        },
        {
            field: "DiscountValue",
            format: "{0:p0}",
            editor: function (container, options) {
                $("<input name='DiscountValue'>")
                .appendTo(container)
                .kendoNumericTextBox(
                  {
                      min: 0,
                      max: 1.00,
                      step: 0.01
                  });
            }
        }],
        editable: true
    });

    function topItemDropDown(container, options) {
        $('<input required data-text-field="TopItemName" data-value-field="TopItemName" data-bind="value:' + options.field + '"/>')
            .appendTo(container)
            .kendoDropDownList({
                autoBind: false,
                dataSource: {
                    transport: {
                        url: '/Discount/GetTopItemName',
                        dataType: "jsonp",
                        type: "POST",
                        contentType: "application/json"
                    }
                }
            });
    }
});

The dropdown is implemented correctly.下拉列表已正确实施。 So there is a dropdown but when i press it it's supposed to post to my controller method and get the values but i get this error:所以有一个下拉菜单,但是当我按下它时,它应该发布到我的控制器方法并获取值,但我收到此错误:

Cannot read property 'data' of undefined无法读取未定义的属性“数据”

Here is my actionmethod:这是我的操作方法:

       public ActionResult GetTopItemName([DataSourceRequest] DataSourceRequest request)
    {
        var customer = custAdapter.GetCustomersByCustomerId(SessionStore.CustomerId);
        return Json(customer, JsonRequestBehavior.AllowGet);
    }

What is data?什么是数据? and why is it undefined?为什么它是未定义的?

I forgot the read function of the datasource so it should look like this:我忘记了数据源的读取功能,所以它应该是这样的:

     transport:{
                        read: {
                            url: '/Discount/GetTopItemName',
                            dataType: "json",
                            type: "POST",
                            contentType: "application/json"
                        },
                 }

I had the same error today and I think the error in your code is in this line:我今天遇到了同样的错误,我认为您的代码中的错误在这一行:

Id: { type: "number" }, //THIS IS WRONG!!!

...should be: ...应该:

Id: { editable: false, nullable: true },

暂无
暂无

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

相关问题 UI网格无法读取未定义的属性数据 - UI Grid Cannot Read Property Data of Undefined 无法读取剑道网格中未定义的属性“最近” - cannot read property 'closest' of undefined in kendo grid 列上的Kendo Grid Grouping - TypeError:无法读取未定义的属性“length” - Kendo Grid Grouping on column - TypeError: Cannot read property 'length' of undefined Kendo ui:未捕获的类型错误:无法读取未定义的属性“toLowerCase” - Kendo ui: Uncaught TypeError: Cannot read property 'toLowerCase' of undefined 捕获TypeError:尝试将数据绑定到Kendo Grid时无法读取未定义(匿名函数)的属性&#39;uid&#39; - Getting Uncaught TypeError: Cannot read property 'uid' of undefined(anonymous function) when trying to bind data to Kendo Grid Kendo Grid在$ timeout中动态添加列,最终出现在&#39;kendo.all.js:121639Uncaught TypeError:Cannot read property&#39;classList&#39;of undefined&#39; - Kendo Grid, dynamically adding column in $timeout, ends up in 'kendo.all.js:121639Uncaught TypeError: Cannot read property 'classList' of undefined' 无法读取未定义的属性“ ui” - Cannot read property 'ui' of undefined React Data Grid (adazzle): TypeError: Cannot read property 'length' of undefined - React Data Grid (adazzle) : TypeError: Cannot read property 'length' of undefined Kendo Grid 在客户端抛出异常:无法读取未定义的属性“长度” - Kendo Grid throw exception on client side : Cannot read property 'length' of undefined 无法更新Kendo网格中的值-无法读取未定义的“数据”属性 - Cannot update value in Kendo-grid - cannot read 'data' property of undegined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM