Looking at the violin, in fact, this was not the best way. Giving the code a quick clean, I got this fiddle: http://jsfiddle.net/colymba/kV8LM/
What I did was add the AddressesRoute route, which IndexRoute redirects to:
App.Router.map(function() { this.route("addresses"); }); App.IndexRoute = Ember.Route.extend({ redirect: function() { this.transitionTo('addresses'); } }); App.AddressesRoute = Ember.Route.extend({ model: function(params){ return [ App.Address.create({'line1': '700 Hansen Wy'}), App.Address.create({'line1': '900 Hansen Wy'}) ]; }, setupController: function(controller, model){ controller.set('content', model); } });
Using naming conventions helps with AddressesRoute , Ember automatically starts Controller and View.
Respectively change the view, its name to addresses and update {{#each}} to the end of the content :
<script type="text/x-handlebars" data-template-name="addresses"> <h2>Index Content:</h2> <p> Length: {{content.length}} </p> <ul> {{#each addresses in controller}} <li>{{line1}}, {{city}}</li> {{/each}} </ul> </script>
The loop {{#each}} can also be simply written {{#each controller}} , because it will look for the default content or model . In both cases, the controller tells View that it must access its controller in order to find the contents for the {{#each}} itemController , otherwise the itemController will not be used (since it does not exist in the view). (which relates to what @intuitivepixel said)
The model and controller are the same as yours:
App.Address = Ember.Object.extend(); App.AddressController = Ember.ObjectController.extend({ city: function(){ return "San Francisco"; }.property() }); App.AddressesController = Ember.ArrayController.extend({ itemController: 'address' }); App.IndexController = Ember.ObjectController.extend();
source share