【发布时间】:2020-12-18 09:31:59
【问题描述】:
使用emberconcat()方法赋值组件属性时,传递条件字符串的正确方法是什么?
考虑以下
{{#my-compontent class=(concat (dasherize model.name)"-row")}}
{{model.name}}
{{/my-component}}
我想要做的是基于model.disabled 属性有条件地添加--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 助手,基于this answer:
{{#my-compontent class=(concat (dasherize model.name)"-row"(ternary model.disabled '--disabled' ''))}}
{{model.name}}
{{/my-component}}
但它崩溃了:
断言失败:找不到名为“三元”的助手
有没有办法做到这一点?如果不是,我将如何使用不同的方法达到相同的效果?
【问题讨论】:
标签: javascript ember.js handlebars.js