如何使用 concat 将条件字符串传递给 ember 组件属性?

使用 ember 方法分配组件属性时传递条件字符串的正确方法是什么concat()?


考虑以下


{{#my-compontent class=(concat (dasherize model.name)"-row")}}

  {{model.name}}

{{/my-component}}

我想要做的是--disabled根据model.disabled属性有条件地添加后缀。


我尝试过的:


{{#my-compontent class=(concat (dasherize model.name)"-row{{if model.disabled '--disabled'}}")}}

  {{model.name}}

{{/my-component}}

导致:


<div class="component-name-row{{if model.disabled '--disabled}}">

  Component name

</div>

我尝试的另一件事是使用ternary助手,基于这个答案:


{{#my-compontent class=(concat (dasherize model.name)"-row"(ternary model.disabled '--disabled' ''))}}

  {{model.name}}

{{/my-component}}

但它崩溃了:


断言失败:找不到名为“ternary”的助手


有什么办法可以做到这一点吗?如果不是,我如何使用不同的方法达到相同的效果?


慕神8447489
浏览 59回答 1
1回答

不负相思意

像往常一样,询问后 5 分钟我自己找到了答案:{{#my-compontent class=(concat (dasherize model.name)"-row(if model.disabled '--disabled')")}}&nbsp; {{model.name}}{{/my-component}}线索是使用(if condition 'string')over {{if condition 'string'}}。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript