Ember:concat attributeBinding,怎么样?

时间:2013-09-22 19:39:31

标签: ember.js concatenation handlebars.js

我需要连接几个变量来创建一个属性,例如我有一组RadioButtons可能会在页面上多次出现 - 动态,首先视图可以显示在时间上,其他的是他们被放置在each循环中,因此每个视图可以出现几次。

所以我不能使用静态name属性,但是如果有几个部分我应该连接,例如结果应该是这样的:

<input name="view1_row0" value="0"> No
<input name="view1_row0" value="1"> Yes

<!-- next row in view1 -->
<input name="view1_row1" value="0"> No
<input name="view1_row1" value="1"> Yes

<!-- next row in view2 -->
<input name="view2_row0" value="0"> No
<input name="view2_row0" value="1"> Yes

等...我可以使用view._parentView.contentIndex轻松获取父视图的ID和/或循环索引,但我不知道如何在一个绑定中连接它们,伪代码看起来像这样: / p>

{{view Ember.RadioButton nameBinding=view.parentView.elementId + "_row" + view._parentView.contentIndex selectionBinding="someVal" value="0"}}

但它当然会在+符号处抛出错误。有什么方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

为什么不将它们作为单独的绑定传递,并将它们连接到Ember.RadioButton的自定义实现中?

{{view App.MyRadioButton elementIdBinding="view.parentView.elementId" contentIndexBinding="view._parentView.contentIndex" selectionBinding="someVal" value="0"}}

然后在App.MyRadioButton(扩展Ember.RadioButton

name: function() {
   return this.get('elementId') + '_row' + this.get('contentIndex');
}.property('elementId', 'contentIndex')

或者您也可以在控制器中执行此操作。