0
votes

Very new to ember and trying to mess around with my first test script. I keep getting the error in the title and it occurs when I try to use handlebars to loop through a data fixture. Any help would be appreciated, thank you!

Link to fiddle

Loop statement that is giving error

{{#each player in controller}}
<tr> <!-- foreach statement here order by wins>loss>ties -->
 <td>{{ name }}</td>
</tr>
{{/each}} 

App.JS

var App = Ember.Application.create({
    LOG_TRANSITIONS: true,
});
// Router
App.Router.map(function(){});

App.PlayersRoute = Ember.Route.extend({
    model: function(){
        return App.Player.find();
    }
});
// Controllers
App.PlayersController = Ember.ArrayController.extend();
// View Helpers
// Models
App.Store = DS.Store.extend({
    revision: 11,
    adapter: 'DS.FixtureAdapter'
});

App.Player = DS.Model.extend({
    name: DS.attr('string'),
    wins: DS.attr('number'),
    losses: DS.attr('number'),
    ties: DS.attr('number'),
    drop: DS.attr('boolean')
});

App.Player.FIXTURES = [{
    id: 1,
    name: 'Joe Jame',
    wins: 2,
    losses: 0,
    ties: 0,
    drop: 'False'
}, {
    id: 2,
    name: 'Froggy Bottom',
    wins: 2,
    losses: 0,
    ties: 0,
    drop: 'False'
}];
2
without seeing any code there will be not much help, how does your script looks like?intuitivepixel
Sorry about that, hit submit too quickly, just posted link to fiddle plus some code.pixeldev

2 Answers

1
votes

The render helper creates a new template/view/controller so in your case you will need to pass in the array of Player objects to allow the playerlist template to have the correct context for rendering.

{{ render "playerlist" content }} 

You also need to change PlayersRoute to IndexRoute otherwise the model hook won't get called and your data won't be loaded.

App.IndexRoute = Ember.Route.extend({
    model: function(){
        return App.Player.find();
    }
});

JSFiddle example

1
votes

One more answer, first I've ported your example to jsbin IMO it's more reliable than jsfiddle, for the kind of setup you have I've changed the render statement to partial and renamed the playerlist template to _playerlist. additionally I've defined in the IndexRoute a model hook to get your fixture data, and this are the results: http://jsbin.com/iceraz/2/edit. It seams to be working now as expected. Since we are using the partial helper there is no need for an extra Playerlist controller nor route, it will be all handled in the IndexRoute.

Hope it helps.