【问题标题】:How to write IF condition in kendo grid?如何在剑道网格中写入 IF 条件?
【发布时间】:2019-06-04 18:00:27
【问题描述】:

我想在剑道网格列中使用 if 条件。但它不起作用。我想把图像取决于条件。有语法错误吗?

<kendo-grid-column field ="Scanned_STS" title="Status" width="20">
  <ng-template kendoGridCellTemplate let-dataItem> "# if(Scanned_STS == 1) { #  #= "<img src=''>" # # } else if (Scanned_STS == 0) { # #= "<img src=''>" # # }"</ng-template>
</kendo-grid-column>

【问题讨论】:

  • 这里有一些很好的例子:stackoverflow.com/questions/28459463/…。 '希望对您有所帮助...
  • 我之前已经尝试过...但它不起作用
  • 1) 你会注意到示例使用了 JS;您直接在 HTML 中执行此操作。您可以尝试更接近示例。 2) 您可能应该 2a) 为图标指定一个类,而不是&lt;img src=...&gt; HTML,然后 2b) 将该类映射到单独的 .css 中的图像。 '希望对您有所帮助...

标签: javascript angular if-statement kendo-grid


【解决方案1】:

您好,如果您使用 Angular,您可以使用 NgIf

import { Component } from '@angular/core';
import { sampleProducts } from './products';

@Component({
    selector: 'my-app',
    template: `
         <kendo-grid [data]="gridData">
            <kendo-grid-column field="ProductName">
                <ng-template kendoGridCellTemplate let-dataItem let-rowIndex="rowIndex">
                    <strong>{{dataItem.ProductName}}</strong>
                      <img *ngIf='dataItem.Discontinued' src='' alt='Item Discontinued'/>
                      <img *ngIf='!dataItem.Discontinued' src='' alt='Item Continued'/>
                </ng-template>
            </kendo-grid-column>
        </kendo-grid>
    `
})
export class AppComponent {
    public gridData: any[] = sampleProducts;
}

【讨论】:

    猜你喜欢
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多