【问题标题】:Kendo Grid Client Template with Condition带有条件的 Kendo Grid 客户端模板
【发布时间】:2013-08-29 18:04:08
【问题描述】:
 columns.Bound(p => p.Active).ClientTemplate("\\#if('#=Active#'=='Y') {\\<input type='button' value='OK' />\\}\\#").Width(150).Title("Status");

但是条件被当作字符串??

#if('Y'=='Y')`enter code here` {
<input type="button" value="OK">
}#  

【问题讨论】:

    标签: asp.net-mvc kendo-ui kendo-grid


    【解决方案1】:

    在剑道模板中使用哈希语法的三种方式:

    1. 呈现文字值:#= #
    2. 呈现 HTML 编码的值:#: #
    3. 执行任意JavaScript代码:# if(...){# ... #}#

    所以在你的代码中你必须写

    columns.Bound(p => p.Active).ClientTemplate(
         "#if(Active=='Y') {#
            <input type="button" value="OK">
          #}#").Width(150).Title("Status");
    

    请注意示例中的# 符号如何将inside 代码与outside 代码分开。当您在代码中时,您不必再次使用 # 来访问变量,这就是为什么 Active 之前可以没有 #。

    【讨论】:

    • 你知道如何使用外部模板(在脚本文件中)吗?我的模板太复杂了,放不了clienttemplate里面...
    • 我认为这应该可行... columns.Bound(p => p.Active).ClientTemplate("# myfunc(data) #");
    • 这对于在模板中排序我的空白值很有用:谢谢。
    • 如果我也想写 else 条件?
    【解决方案2】:

    试试这个,

     columns.Bound(p => p.Active).ClientTemplate(
                    "# if (IsServiceExist) { #" +
                        "<input type='button' value='OK' />"+
                    "# }#").Width(150).Title("Status");
    

    【讨论】:

    • 如果我想要多个条件会怎样?例如:if (IsServiceExist && !IsEmail)。方法正确吗?
    • @Metaphor 是的,您可以在 ClientTemplate 中执行此操作
    • 这对我很有帮助。谢谢贾敏。来我的网站translateyar.ir
    【解决方案3】:

    希望你能得到解决方案....

    columns.Bound(p => p.IsActive)
        .ClientTemplate(
            "\\# if (IsActive != false) { \\#" +
                "\\<input type=\"checkbox\" id=\"checkBox\" class=\"parentCheckBox\" window-call=\"template\" checked/>\\" +
            "\\# } else { \\#" + 
                "\\<input type=\"checkbox\" id=\"checkBox\" class=\"parentCheckBox\" window-call=\"template\" />\\" + 
            "#\\ } \\#")
        .Width(10);
    

    【讨论】:

      【解决方案4】:

      要在您的剑道模板中呈现数据值,您可以使用以下内容作为指导:

      columns.Template(@<text></text>)
          .ClientTemplate("#if (Field3 == true) {#"
          + "<a onclick='jsFoo(#=Id#)' href='\\#'></a> "
          + "#} #").Width(70).Title("ColA");
      

      【讨论】:

      • 这个比原来的答案好
      【解决方案5】:
      columns.Bound(searchModel => searchModel.Value).ClientTemplate(
          "#if(Name=='DevboardTask'){# " + 
              "<a href='\\#UpdateStatusWindow' onclick=\"javascript:openflexpmtask('#=Value#');\">#=Value#</a> " +
          "#} else {# " +
              "<a\">#=Value#</a> " +
          "#}#");
      

      这可能会对您有所帮助。这只是一个例子......

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多