【问题标题】:else if condition in js render templateelse if条件在js渲染模板中
【发布时间】:2013-12-11 14:15:05
【问题描述】:

您好,我在 js 渲染模板中使用了以下代码 sn-p。

{{if Expanded}}e-gridtreerowexpand {{else (!Expanded)&&(HasChildGridRecords)}} e-gridtreerowcollapse {{/if}}

在这个 else 条件下不起作用。在 Expanded 中,HasChildGridRecords 是要呈现的数据对象中存在的属性。

如何解决这个问题。

【问题讨论】:

    标签: javascript jsrender


    【解决方案1】:

    应该可以。 (尽管在 if 中已经测试过 (!Expanded) 是多余的)。

    你可以写

    {{if Expanded}}
      e-gridtreerowexpand
    {{else HasChildGridRecords}}
      e-gridtreerowcollapse
    {{/if}}
    

    (也不需要括号)

    如果 Expanded 为真,您将获得第一个渲染块。

    如果 HasChildGridRecords 为真,而 Expanded 为假,则得到第二个块。

    【讨论】:

    • 嗨,谢谢你的帮助,对我来说工作正常
    • 嗨 Borris,它是否支持 else if 语法?
    • @LakshithaUdara: 是的,{{else someExpression}} 表现为“else if”,而 {{else}} 表现为“else”参见jsviews.com/#iftag 的最后一部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-26
    • 2019-05-03
    • 2023-02-22
    • 1970-01-01
    • 2019-07-28
    • 2016-11-13
    • 1970-01-01
    相关资源
    最近更新 更多