渲染具有特定ID属性的Ember.Checkbox

时间:2013-04-22 02:32:51

标签: ember.js handlebars.js

在Ember中,将Ember.View的ID属性显式设置为动态的正确方法是什么?如果可能的话,我想避免仅为了这一点功能而扩展Ember.View。使用下面的示例,我尝试设置“id'和' elementId'像{{id}}这样的东西无济于事。

<script type="text/x-handlebars" id='_task'>
  <label class='for-checkbox' for="task-{{unbound id}}"></label>
  {{view Ember.Checkbox checkedBinding="complete" elementId="task-{{id}}"}}
  {{description}}
</script>

<script type="text/x-handlebars" id="index">
  <ul class='tasks'>
    {{#each tasks}}
      {{partial "task"}}
    {{/each}}
  </ul>
</script>

1 个答案:

答案 0 :(得分:2)

如果您正在写{{... {{...}} ...}}之类的内容,那么您可能做错了。

<label class="for-checkbox" {{bindAttr for="name"}}></label>
{{view Ember.Checkbox checkedBinding="complete" nameBinding="name"}}

如果name是任务的计算属性,那么就应该这样做。