Code for view is
Ember.View.extend({
template: Ember.Handlebars.compile(html), // html is in string
content: function() {
return [
{ Title: "Dashboard", ID: "dashboard" },
{ Title: "Invoices", ID: "invoices" },
{ Title: "Expenses", ID: "expenses" },
{ Title: "People", ID: "people" },
{ Title: "Reports", ID: "reports" },
{ Title: "Settings", ID: "settings" }
]},
iconClass: function(link){
return "icon icon-" + link.ID
}
});
Template (show above as “html”) looks like this:
<ul>
{{#each link in view.content}}
<li>
<a>
<span class="icon" {{bindAttr class="view.iconClass(link)"}}></span>
<span class="title">{{link.Title}}</span>
</a>
</li>
{{/each}}
</ul>
This renders
<span class="icon" data-bindattr-2="2"></span>
So additional class attribute is not rendered. Am I doing something wrong with scope or?
NOTE:
I changed my code to show what I want to do.
EDIT
According to the new question, you’ll have to use an
Ember.CollectionView:As you can see, each
itemViewClasshas a propertyiconClasswhich depends on itscontent.id.Now you’ll have to add the collection view in the template of the view
FooView:Here we are using the
{{collection}}Handlebars helper, and we bind the content of theFooViewto theFooCollectionView.It will automatically create an
itemViewClassinstance for each object in the CollectionView.content, set the its to the associated object, and add it to the view.I suggest you to read the Ember.CollectionView documentation.
And you could try this solution in this JSFiddle.