在 Kendo UI 网格的列中的命令函数中传递值
Passing a value in Command function in a column for Kendo UI Grid
我想在 Kendo UI 网格中添加一个按钮,它将重定向到不同的站点 URL 是在基于环境和 ID 的函数中动态创建的该相应行的字段在 URL 中传递。所以我在网格中添加了一个命令列,但我不确定如何将 ID 传递给该函数。请帮忙 。
以下对我不起作用
{ command: { text: "View", click: "getredirectURL(#=Id#)" }, title: " ", width: "100px" }
问题是您配置的 click
事件有误。根据 documentation,您需要设置单击命令按钮时执行的 JavaScript 函数。您不能使用模板设置此函数的参数(即 #=Id#
)。该函数接收一个 jQuery 事件作为参数(复制粘贴语句)。
您需要执行以下操作:
click: function(e) {
// e.target is the DOM element representing the button
var tr = $(e.target).closest("tr"); // get the current table row (tr)
// get the data bound to the current table row
var data = this.dataItem(tr);
//the "data" variable is now the entire "object" and has properties
//you now have access to the Id property so just call your function
getredirectURL(data.Id);
}
您可能想要添加一个 debugger;
并开始检查函数内的 e
事件和 this
对象。里面有很多有趣的东西。
我想在 Kendo UI 网格中添加一个按钮,它将重定向到不同的站点 URL 是在基于环境和 ID 的函数中动态创建的该相应行的字段在 URL 中传递。所以我在网格中添加了一个命令列,但我不确定如何将 ID 传递给该函数。请帮忙 。 以下对我不起作用
{ command: { text: "View", click: "getredirectURL(#=Id#)" }, title: " ", width: "100px" }
问题是您配置的 click
事件有误。根据 documentation,您需要设置单击命令按钮时执行的 JavaScript 函数。您不能使用模板设置此函数的参数(即 #=Id#
)。该函数接收一个 jQuery 事件作为参数(复制粘贴语句)。
您需要执行以下操作:
click: function(e) {
// e.target is the DOM element representing the button
var tr = $(e.target).closest("tr"); // get the current table row (tr)
// get the data bound to the current table row
var data = this.dataItem(tr);
//the "data" variable is now the entire "object" and has properties
//you now have access to the Id property so just call your function
getredirectURL(data.Id);
}
您可能想要添加一个 debugger;
并开始检查函数内的 e
事件和 this
对象。里面有很多有趣的东西。