How to use child view when iterating over a collection of items in EmberJs
-
28-10-2019 - |
Question
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.
Solution
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}}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow