我正在尝试为一条路线返回多个模型,是的,我正在使用 RSVP.Hash(GitHub 链接):
App.GamesIndexRoute = Ember.Route.extend({
model: function () {
return new Ember.RSVP.Hash({
player: App.LocalPlayer.singleton(this.store),
games: [{id: 1, name: "Game 1"}, {id: 2, name: "Game 2"}]
});
},
setupController: function(controller, models) {
this._super(controller, models);
controller.set("player", models.player);
}
});
问题是,其中一个对象来自承诺本身,因为我只想从该模型中找到第一个对象(GitHub链接):
App.LocalPlayer = DS.Model.extend({
name: DS.attr("string"),
playerId: DS.attr("string")
});
App.LocalPlayer.singleton = function (store) {
return new Ember.RSVP.Promise(function (resolve, reject) {
store.find("localPlayer").then(function (things) {
var p = things.get("firstObject");
if(!p) {
p = store.createRecord("localPlayer");
}
resolve(p);
reject({error: "Error loading LocalPlayer"});
});
});
};
当我在创建 LocalPlayer 对象后尝试转到 games.index 路由时,它说:“处理路由时出错:games.index undefined is not a function TypeError: undefined is not a function”
回购在GitHub 上- 完全开源。请帮忙。