如何在每个中设置itemController(ember 1.11 beta3)?

Jes*_*Top 5 javascript each handlebars.js ember.js

我想尝试使用:

{{#each content as |product index|}}
  {{index}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)

但我的应用程序有itemContoller,如下所示:

{{#each product in content itemController='product'}}
Run Code Online (Sandbox Code Playgroud)

如果我这样设置:

{{#each content as |product index| itemController='product'}}
Run Code Online (Sandbox Code Playgroud)

它不起作用!我找到了所有的余烬指南而没有找到答案.

请帮忙.

Kal*_*man 7

控制器(Object,ArrayitemController)正在消失.新方法是使用组件.

因此,您将定义一个组件,而不是您的项目控制器:

App.MyProductComponent = Ember.Component.extend({
  myIndex: function(){
    return this.get('passedIndex') + 1;
  }.property('passedIndex')
});
Run Code Online (Sandbox Code Playgroud)

然后,在你的#each帮助器中,你将使用它如下:

<script type="text/x-handlebars" data-template-name="index">
  <ul>
    {{#each model as |product index|}}
      {{ my-product passedIndex=index product=product }}
    {{/each}}
  </ul>
</script>
Run Code Online (Sandbox Code Playgroud)

工作方案在这里

请参阅以下链接并搜索itemController- https://github.com/emberjs/rfcs/pull/15