我尝试在kendo-grid模板中实现IF条件,但模板位于命令内部。条件发送给我一个错误。什么是错的,我该怎么办?
这是我的代码:
command:{
text: "Tarea",
field: "Comentario",
click: function (e) {
console.log("Hello")
},
template:'#if(Comentario != 0){# <a href="\\#" class="k-button k-button-icontext k-grid-Tarea"><span class="fa fa-2x fa fa-pencil-square-o text-default"></span></a> # } else {# <a href="\\#" class="k-button k-button-icontext k-grid-Tarea"><span class="fa fa-2x fa fa-pencil text-default"></span></a> #} #',
},
答案 0 :(得分:1)
命令对象没有模板属性。您可以改为使用列模板:
$("#grid").kendoGrid({
columns: [
"name",
"Comentario",
{
field: "Comentario",
title: "Tarea",
template: '#if(Comentario != 0){# <a href="\\#" class="k-button k-button-icontext k-grid-Tarea"><span class="fa fa-2x fa fa-pencil-square-o text-default"></span></a> # } else {# <a href="\\#" class="k-button k-button-icontext k-grid-Tarea"><span class="fa fa-2x fa fa-pencil text-default"></span></a> #} #'
}],
dataSource: [ { Comentario: "0", name: "Name1" }, { Comentario: "1", name: "Name1" } ]
});
然后你可以使用点击处理程序和网格的dataItem方法来处理自定义字体真棒按钮的点击次数:
$("#grid").on("click", ".k-grid-Tarea", function(e) {
var grid = $("#grid").data("kendoGrid");
var dataItem = grid.dataItem($(this).closest("tr"));
alert(dataItem.name); // displays name column
});