dariusriggins
dariusriggins

Reputation: 1444

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

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.

Upvotes: 2

Views: 379

Answers (1)

rharper
rharper

Reputation: 2438

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}}

Upvotes: 1

Related Questions