为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕神8447489 2023-12-14 14:14:01
使用 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”的助手有什么办法可以做到这一点吗?如果不是,我如何使用不同的方法达到相同的效果?
查看完整描述

1 回答

?
不负相思意

TA贡献1777条经验 获得超10个赞

像往常一样,询问后 5 分钟我自己找到了答案:


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

  {{model.name}}

{{/my-component}}

线索是使用(if condition 'string')over {{if condition 'string'}}。


查看完整回答
反对 回复 2023-12-14
  • 1 回答
  • 0 关注
  • 55 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信