You can either do what Kristofor Selden suggested in this fiddle http://jsfiddle.net/krisselden/6fAHZ/ (bind the content
array in the itemViewClass
) or you can do it as follows:
Fiddle: http://jsfiddle.net/ppanagi/WhGjR/
App = Ember.Application.create();
App.collectionView = Ember.CollectionView.create({
content: [
{ key: 'value one' },
{ key: 'value two' }
],
itemViewClass: Ember.View.extend({
template: Ember.Handlebars.compile('{{view.content.key}}')
})
});
App.collectionView.append();
The default context of templates are now controller variables, so {{foo}}
will return the value of the controller variable foo
. If you need the value of bar
variable of the View, use {{view.bar}}
.
Follow up: Yet another way to change the context is to use {{with}}
:
App.collectionView = Ember.CollectionView.create({
template: Ember.Handlebars.compile('{{#with view}} {{content.key}} {{/with}}')
});