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

I want to try:

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

But my application has an itemContoller, for example:

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

If I installed this:

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

This does not work! I found all the concealers and could not find the answer.

Any help please.

+5
source share
3 answers

Controllers ( Object , Array and itemController ) are leaving. A new way to do this is to use a component.

So, instead of your element controller, you should define a component:

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

Then inside your #each you will use it like this:

 <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 search for itemController - https://github.com/emberjs/rfcs/pull/15

+7
source

Really? I mean, there are many cases where I think that creating a component to display the calculated values ​​based on the properties (s) of the controller model will be excessive ..... What if I just want a string (I don’t need a <div> thing added by ember for each component).

Create a helper (s)? Wow.

0
source

@ user3443096,

If you do not want the div tags inserted by ember to use the tagName: "" property as follows:

 App.InvoiceItemsComponent = Ember.Component.extend({ tagName: '' }); 

Now divs around your component will not be inserted.

0
source

Source: https://habr.com/ru/post/1214145/


All Articles