简体   繁体   English

迭代中的Ember组件和动态属性

[英]Ember component and dynamic attributes over iteration

How can I add support to my custom Ember component for appending dynamic attributes and also action? 如何为自定义Ember组件添加支持以添加动态属性和动作? 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; 现在,我要遍历API响应,并在模板中具有动态属性以及以下操作支持;

{{#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 PS:我无法控制自定义组件my-radiobutton,因为它是常见的/外部的,所以我希望模板或控制器中的任何内容

You might be looking for the concat helper 您可能正在寻找concat助手

{{#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}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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