[英]Ember.js: route returning multiple models including a promise, gives error
I am trying to return multiple models for a route, and, yes, I am using RSVP.Hash ( GitHub link ): 我正在尝试为一条路线返回多个模型,是的,我正在使用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);
}
});
The problem is, one of the objects is coming from a promise itself as I want to find only the first object from that model ( GitHub link ): 问题是,其中一个对象来自promise本身,因为我只想从该模型中找到第一个对象( 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"});
});
});
};
When I try and go to the games.index route after having created a LocalPlayer object, it says: "Error while processing route: games.index undefined is not a function TypeError: undefined is not a function" 当我创建LocalPlayer对象后尝试转到games.index路由时,它说:“处理路由时出错:games.index undefined不是函数TypeError:undefined不是函数”
The repo is on GitHub here - totally open source. 该仓库位于GitHub上 -完全开源。 Please help. 请帮忙。
Hahaha.... I realised my mistake. 哈哈哈...。我意识到自己的错误。 It was my fault for not reading properly, and it made me lost about 2 days of my life. 这是我没有正确阅读的错,这使我失去了大约两天的生命。 Oh well. 那好吧。
RSVP.Hashes are initialized like this: RSVP.Hash初始化如下:
return Ember.RSVP.hash({ ... })
NOT like I was doing: 不像我在做的那样:
return new Ember.RSVP.Hash({ ... })
Problem solved. 问题解决了。 I wish the error reporting was as bit more clearer. 我希望错误报告更加清晰。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.