I’ve prepared a Fiddle to better expose the problem.
Code:
App = Ember.Application.create();
App.MyView = Ember.View.extend({ templateName: "MyView" });
App.myCollectionView = Ember.CollectionView.create({
itemViewClass: App.MyView,
content: [
Ember.Object.create({ name: "World" }),
Ember.Object.create({ name: "Foo" }),
Ember.Object.create({ name: "Bar" })
]
});
$(function() { App.initialize(); });
View :
<script type="text/x-handlebars">
{{collection App.myCollectionView}}
</script>
<script type="text/x-handlebars" data-template-name="MyView">
<h1>Hello, {{name}}!</h1>
</script>
What am I doing wrong here?
First, the
{{collection}}helper needs aEmber.Viewclass instead of anEmber.Viewinstance. You have to replaceEmber.CollectionView.create()withEmber.CollectionView.extend.Next, in your template, you have to replace
{{name}}with{{view.content.name}}, according to View context changes.Here is your updated JSFiddle: http://jsfiddle.net/AzV4f/
EDIT
Writing
{{name}}meanscontext.name, where context is usually the controller (see source code). And asEmber.ObjectController,Ember.ArrayControllerare just proxy, these property are delegated to their content(see ObjectProxy source code).So you have to write
{{view.content.name}}, because you want thenameproperty of theview.content.As @tomdale said in this gist comment:
And you can see the JSFiddle with a controller, without specifying
view: JSFiddle