【问题标题】:Kendo grid button click arguments剑道网格按钮单击参数
【发布时间】:2014-11-24 18:57:30
【问题描述】:

我有一个带有按钮列的剑道网格。单击按钮时,我希望它以行的数据作为参数调用 javascript 函数。这是我目前所拥有的

$(grd).kendoGrid({
    dataSource: ds,
    detailInit: detailInit,
    columns: [ {field: "foo", title: "bar" },
               {field: "Y" },
               {command: { text: "MyButton", click: doStuff } } ]
    });

function doStuff(e)
{
    //e is click events but I want to pass in data from the row instead
    //following is code I found here but item is null for me
    var row = $(this).closest("tr");
    var item = $(grd).data("kendoGrid").dataItem(row);
}

【问题讨论】:

    标签: kendo-ui kendo-grid


    【解决方案1】:

    这将为您提供与单击按钮的行有关的数据。

    function doStuff(e) {
    
        var tr = $(e.target).closest("tr");    // get the current table row (tr)
        var item = this.dataItem(tr);          // get the date of this row
    
        alert(item.PropertyName);
    }
    

    【讨论】:

    • 好吧,也许我使用了错误的代码?我没有选择一行,只是单击列中的按钮。目前,这是我在 console.log 中看到的 tr: [prevObject: n.fn.init[1], context: undefined, jquery: "1.11.0", constructor: function, selector: ""...]context: undefinedlength: 0prevObject: n.fn.init[1]0: T.extend.initlength: 1__proto__: n[0]__proto__: n[0]
    • 我编辑了我的答案以更好地澄清。此代码块将起作用。
    • 感谢您的快速回复!
    猜你喜欢
    • 2014-06-20
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多