【问题标题】:MVC Kendo Grid - Uncaught TypeError: Cannot read property 'id' of undefinedMVC Kendo Grid - 未捕获的类型错误:无法读取未定义的属性“id”
【发布时间】:2015-04-22 11:20:04
【问题描述】:

我有一个剑道网格和模板列

columns.Template(t => t.id)
    .ClientTemplate("<button style='margin:2px' type='button' class='btn btn-success btn-xs' data-toggle='tooltip' data-placement='left' title='Change' onclick='getID()'><span class='glyphicon glyphicon-cog'></span></button>")
    .Width(30)
    .HtmlAttributes(new { @style = "text-align:center" });

function getID(e) {
    debugger;
    var grid = $("#Grid").data("kendoGrid");
    var model = model.id
    alert(model.id);
}

我刚刚收到此错误:

未捕获的类型错误:无法读取未定义的属性“id”。

为什么?如何获取单击按钮的模型 ID?

【问题讨论】:

  • 逻辑有缺陷。您将model 重新定义为model.id,然后尝试检索现在可能是字符串或int 的id 属性。

标签: jquery model-view-controller model kendo-ui grid


【解决方案1】:

我假设您正在尝试在 javascript 中访问 razor 中的模型变量,但您不能这样做。

 function getID(e) {
    debugger;
    var grid = $("#Grid").data("kendoGrid");
    var dataItem= grid.dataItem(grid.select());//gets the dataItem for the current row
    alert(dataItem.id);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 2015-01-06
    • 2017-07-26
    相关资源
    最近更新 更多