Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set itemController in each as (ember 1.11 beta3)?

I want to try use:

{{#each content as |product index|}}
  {{index}}
{{/each}}

But my app has the itemContoller, like this:

{{#each product in content itemController='product'}}

If I set this:

{{#each content as |product index| itemController='product'}}

It doesn't work! I found all of the ember guides and did not find the answer.

Any help please.

like image 918
JeskTop Avatar asked Feb 25 '15 09:02

JeskTop


1 Answers

Controllers (Object, Array and itemController) are going away. The new way to do things is by using a component.

So, instead of your item controller, you would define a component:

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

Then, inside your #each helper you would use it as follows:

<script type="text/x-handlebars" data-template-name="index">
  <ul>
    {{#each model as |product index|}}
      {{ my-product passedIndex=index product=product }}
    {{/each}}
  </ul>
</script>

Working solution here

See the following link and do a search for itemController - https://github.com/emberjs/rfcs/pull/15

like image 126
Kalman Avatar answered Nov 01 '22 15:11

Kalman