【问题标题】:how can i implement a IF statement in command inside Kendo-grid?如何在 Kendo-grid 内的命令中实现 IF 语句?
【发布时间】:2018-02-14 00:09:39
【问题描述】:

我尝试在 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> #} #',
          },

【问题讨论】:

    标签: javascript jquery kendo-ui kendo-grid


    【解决方案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       
    });
    

    DEMO

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-21
      • 2014-11-11
      • 1970-01-01
      • 2017-08-09
      • 2016-05-27
      相关资源
      最近更新 更多