0

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'
}];
4

2 回答 2

1

还有一个答案,首先我将您的示例移植到 jsbin IMO,它比 jsfiddle 更可靠,对于您的设置,我已将render语句更改partial为并将playerlist模板重命名为_playerlist. 另外,我在IndexRouteamodel钩子中定义了获取您的夹具数据,结果如下:http: //jsbin.com/iceraz/2/edit。它现在正在按预期工作。由于我们使用的是partial帮助程序,因此不需要额外的Playerlist控制器或路由,所有这些都将在IndexRoute.

希望能帮助到你。

于 2013-07-08T20:35:38.707 回答
1

render帮助程序创建一个新的模板/视图/控制器,因此在您的情况下,您需要传入Player对象数组以允许playerlist模板具有正确的渲染上下文。

{{ render "playerlist" content }} 

您还需要更改PlayersRouteIndexRoute否则model不会调用挂钩并且不会加载您的数据。

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

JSFiddle 示例

于 2013-07-08T20:25:32.590 回答