How to use child view when iterating over a collection of items in EmberJs

StackOverflow https://stackoverflow.com/questions/9388129

  •  28-10-2019
  •  | 
  •  

문제

I have a view that has a list of items that I'm iterating over in a template, and rendering that view inside of it as a list item of a . If I use the global name for the template, it works just fine, but I don't want to define that template globally, I want to define it on the current view as a child view. If I reference it outside of the {{#each}} block, it works, but not inside. Is there any way to do this?

{{#each items}}
  {{#view Em.App.RecentItemView contentBinding="this"}}
    <a href="#">{{content.Title}}</a>
  {{/view}}
{{/each}}

The view in context also has an itemView: Em.View.extend({}) on it that I would rather use.

도움이 되었습니까?

해결책

Would using the {{#collection}} helper instead work for you? Here's a jsfiddle with a working example.

{{#collection contentBinding="items" itemViewClass="itemView"}}
     <a href="#">{{content.Title}}</a>
{{/collection}}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top