亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 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 關注
  • 177 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號