[英]“if” handlebar inside a component handlebar in Ember.js
In Ember, I know that I can include classes with if statements using the {{if}} handlebar. 在Ember中,我知道我可以使用{{if}}把手包含带有if语句的类。 However, how can I do this inside a component handlebar?
但是,我怎样才能在组件车把内做到这一点?
For example, how can I do something like this: 例如,我该怎么做这样的事情:
{{myComponent class="my-class {{if isThisTrue 'true-class' 'false-class'}}" }}
Since the curly braces can't be nested there is a syntax called nested helper to do so, and it works for most of the helpers like if
, unless
, concat
, and family: 由于花括号不能嵌套,因此有一种称为嵌套助手的语法,它适用于大多数助手,如
if
, unless
, concat
和family:
{{myComponent class=(concat "my-class " (if isThisTrue 'true-class' 'false-class'))}}
You have to use concat
here since you're putting together a static and a dynamic portion of the string together. 你必须在这里使用
concat
,因为你将字符串的静态和动态部分组合在一起。
您可以使用,
{{my-component class="my-class" classNameBindings="isThisTrue:true-class:false-class"}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.