简体   繁体   中英

Ember component and dynamic attributes over iteration

How can I add support to my custom Ember component for appending dynamic attributes and also action? I have my custom component as

{{my-radiobutton name='myName' value='RadioButton1' selection=this.selectedRadio}}

Now I want to iterate over API response and have dynamic attributes in my template as well as action support as below;

{{#each model.myApi as |myApi|}}
{{#if someCondition}}
{{my-radiobutton name='myName_{{myApi.someId}}' value='someAction_{{myApi.someId}}' selection=this.selectedRadio {{action 'actionClicked'}}}}
{{else}}
{{my-radiobutton name='myName_{{myApi.someId}}' value='someAction_{{myApi.someId}}' selection=this.selectedRadio {{action 'actionClicked'}}}}
{{/if}}
{{/each}}

Is it possible to do that?

PS: I do not have control over the custom component my-radiobutton, since it is kind of common/external, so I'll prefer anything in the template or my controller

You might be looking for the concat helper

{{#each model.myApi as |myApi|}}
  {{#if someCondition}}
    {{my-radiobutton name=(concat "myName_" myApi.someId) value=(concat "someAction_" myApi.someId) selection=this.selectedRadio {{action 'actionClicked'}}}}
  {{else}}
     {{my-radiobutton name=(concat "myName_" myApi.someId) value=(concat"someAction_" myApi.someId) selection=this.selectedRadio {{action 'actionClicked'}}}}
  {{/if}}
{{/each}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM