asp.net-mvc 带条件的剑道网格客户端模板

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18457851/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 03:07:14  来源:igfitidea点击:

Kendo Grid Client Template with Condition

asp.net-mvckendo-uikendo-grid

提问by user2720297

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

but condition is taken as string??

但条件被视为字符串?

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

回答by Ohlin

There are three ways to use the hash syntax in a Kendo template:

在 Kendo 模板中可以通过三种方式使用哈希语法:

  1. Render literal values: #= #
  2. Render HTML-enocded values: #: #
  3. Execute arbitrary JavaScript code: # if(...){# ... #}#
  1. 呈现文字值: #= #
  2. 呈现 HTML 编码的值: #: #
  3. 执行任意 JavaScript 代码: # if(...){# ... #}#

So in your code you would have to write

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

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

Notice in the sample how the #signs separate insidecode from outsidecode. When you're inside code you don't have to use #again to access a variable and that's why Active can be without #before.

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

回答by Jaimin

Try this,

尝试这个,

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

回答by Bhavsar Jay

I hope you get the solution....

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

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);

回答by callisto

To have data values rendered in your Kendo template you could use the following as a guide:

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

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

回答by GoviNd Gopi

columns.Bound(searchModel => searchModel.Value).ClientTemplate(
    "#if(Name=='DevboardTask'){# " + 
        "<a href='\#UpdateStatusWindow' onclick=\"javascript:openflexpmtask('#=Value#');\">#=Value#</a> " +
    "#} else {# " +
        "<a\">#=Value#</a> " +
    "#}#");

This might help you. This is just an example...

这可能对你有帮助。这只是一个例子...