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

﹥>﹥吖頭↗ 提交于 2019-12-05 10:34:00

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

Really? I mean, there are many cases where I think creating a component for displaying computed values based on the property(s) of the controller's model would be overkill..... What if I just want a string (I don't need the <div> thing added by ember for each component).

Creating helper(s) then? Wow.

@user3443096,

If you wouldn't like to have div tags inserted by ember use tagName: "" property like this:

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

Now, divs around your component will not be inserted.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!