我如何告诉 Ember 不仅要检索匹配列表,还要获取每个关联玩家的对象?
在我的路由器中,我有:
App.MatchesRoute = Ember.Route.extend
model: ->
App.Match.find()
这是我的 JSON 数据的用途localhost:3000/matches.json
{"matches":[{"id":1,"player_one":{"id":1,"name":"Lex"},"player_two":{"id":20,"name":"Superman"}}]}
更新以提供更多信息 03/15/13
这是matches.emblem
(标志是haml-slim-like-handlebars)
#matches
each match in controller
linkTo "match" match class="panel six columns"
p Match between {{match.player_one.name}} and {{match.player_two.name}}
我们成功获取了Match
对象,我可以调用id
它(未显示),但我们需要获取 and 的名称match.player_one
,match.player_two
它们返回未定义。
匹配
App.Match = DS.Model.extend
player_one: DS.belongsTo('App.Player')
player_two: DS.belongsTo('App.Player')
播放器
App.Player = DS.Model.extend
name: DS.attr('string')