javascript - 0x800a138f - JavaScript 运行时错误 : The value of the property '' is null or undefined, 不是函数对象

标签 javascript jquery kendo-ui kendo-grid kendo-asp.net-mvc

1> 我有剑道网格,其中一列有一个按钮。我已将 javascript 函数分配给按钮的 onclick 事件。 javascript 进行 ajax 调用。但是当我点击按钮时出现错误

0x800a138f - JavaScript 运行时错误:属性“DoSomething”的值为 null 或未定义,而不是 Function 对象

我尝试将 onclick 设置为“javascript:DoSomething();”没有运气

2> 如果可能的话,我还想将“BatchKey”值传递给函数

<div>
    @(Html.Kendo().Grid< BatchDetail>()
    .Name("grid")
    .Columns(col =>
    {
        col.Bound(p => p.BatchKey);
        col.Bound(p => p.OriginalCost);
        col.Bound(p => p.Status);
        col.Bound(p => p.LastFileName);
        col.Bound(p => p.FileID).ClientTemplate(
            "# if (Status == \"Error\") { #" +
            "<button id=\"btnResolve\" class=\"resolve-button\" onclick=\"DoSomething();\">Resolve</button>" +
            "#}#"
            ).Title("Action");
    })
    .AutoBind(true)
    .Pageable()
    .Sortable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Read(read => read
            .Action("GetData", "Detail", new { ID = Model.ID })))
    )
</div>
function DoSomething()
{   
    $.ajax({
        url: "www.msn.com",
        success: function (result)
        {
            $("#div1").html(result);
        }
    })
}

最佳答案

按钮ID需要是唯一的,所以你不能这样使用它。您可以像这样传递 BatchKey:

 col.Bound(p => p.FileID).ClientTemplate(
     "# if (Status == \"Error\") { #" +
         "<button class=\"resolve-button\" onclick=\"DoSomething(this, '#= BatchKey #');\">Resolve</button>" +
      "#}#"
            ).Title("Action");

function DoSomething(button, batchKey)
{   
    $.ajax({
        url: "www.msn.com",
        success: function (result)
        {
            $("#div1").html(result);
        }
    })
}

我已经在自己的网格上对此进行了测试,效果很好。如果仍然不起作用,则说明您发布的代码之外的代码存在问题。

关于javascript - 0x800a138f - JavaScript 运行时错误 : The value of the property '' is null or undefined, 不是函数对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29836042/

相关文章:

javascript - DOM属性改变调试

javascript - 困惑为什么我在 Node.js (require.js) 中得到这个错误

javascript - MySQL/AJAX/jQuery 自动完成

knockout.js - 使用 Knockout-Kendo.js 动态启用/禁用 kendo datepicker

javascript - 如何根据列值删除 kendo ui 网格行

javascript - Jquery 和 CSS3 旋转

javascript - Safari 剪贴板错误 "TypeError: undefined is not an object"

javascript - Bootstrap日期选择器关闭函数

javascript - 在页面加载时重绘完整日历

json - Odata:不支持查询参数 '$count'