【问题标题】:Ember if helper for component attributeEmber if 组件属性的助手
【发布时间】:2018-08-14 06:03:59
【问题描述】:

我想做以下事情

{{my-field-component cssClass="(if someCondition 'class1' 'class2')"}}

由于某种原因,上述方法不起作用。 这样做的正确方法是什么?

P.S:我想为自定义组件属性而不是 DOM 元素执行此操作?

【问题讨论】:

    标签: javascript jquery ember.js


    【解决方案1】:

    正确的做法是省略引号:

    {{my-field-component cssClass=(if someCondition 'class1' 'class2')}}
    

    如果您需要为该属性添加一些静态字符串,您可以使用concat helper:

    {{my-field-component 
      cssClass=(concat 
        'static classes ' 
        (if someCondition 'class1' 'class2') 
        ' some other static classes'
      )
    }}
    

    在组件中,您还有classNameBindings 用于类名。

    【讨论】:

    • 完美...非常感谢!!
    猜你喜欢
    • 2015-12-24
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    • 1970-01-01
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多