【问题标题】:How to send "this" as a function parameter in a client template of a bound column in an mvc kendo ui grid?如何在 mvc kendo ui 网格中绑定列的客户端模板中将“this”作为函数参数发送?
【发布时间】:2014-09-04 07:25:45
【问题描述】:

我有一个 kendo ui 网格,它有一个使用客户端模板的绑定列。客户端模板包含一个带有 onclick 事件的 html 按钮,看起来像

columns.Template(e => e.ConfirmationNumber).ClientTemplate("<button class='btnStartStopClock' onclick='StartStopPSAClock(this, #= ConfirmationNumber #, \"#= Description #\")'>Start</button>").HtmlAttributes(new { id = "btnStartStop_\\#= ConfirmationNumber\\#" }).Title("").Width(15);

我想知道如何正确地将“this”(按钮)作为参数发送到 onclick 函数。我目前拥有的东西打破了它。

感谢您的帮助

【问题讨论】:

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


    【解决方案1】:

    您可以使用以下 Javascript 并更改您的列代码如下:

    columns.Template(e => e.ConfirmationNumber).ClientTemplate("<button class='btnStartStopClock' onclick='StartStopPSAClock(event, #= ConfirmationNumber #, \"#= Description #\")'>Start</button>").HtmlAttributes(new { id = "btnStartStop_\\#= ConfirmationNumber\\#" }).Title("").Width(15);
    
    
    function StartStopPSAClock(event, confNumber, descrip) {
        alert("ConfirmationNumber:  " + confNumber);
        alert("Description:  " + descrip);
    
        //Get Parent Button object as well Parent of Button.
        alert("Button ID: " + event.target.id);
        alert("Button Parent ID: " + event.target.parentElement.id);
    }
    

    Demo

    【讨论】:

    • 完美,谢谢!我不知道 event 关键字。欣赏学习新事物。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-23
    相关资源
    最近更新 更多