【发布时间】:2015-04-28 19:59:55
【问题描述】:
在我的骨干应用程序内的追随者集合中,我有以下内容
window.Curate.Collections.Following = Backbone.Collection.extend({
model: Curate.Models.User,
initialize: function (models, options) {
this.add(models);
this.user_id = options.user_id;
},
url: function () {
return '/api/users/' + this.user_id + '/following';
},
parse: function(response){
this.page_number = parseInt(response.page_number);
this.total_pages = parseInt(response.total_pages);
return response.users;
}
});
window.Curate.Collections.following = new Curate.Collections.Following();
Curate.Collections.following.fetch({
data: { page: 1 }
});
令我困惑的是,在初始化对象中,options.user_id 中的 user_id 抛出错误
Uncaught TypeError: Cannot read property 'user_id' of undefined
现在,这就是我想要它做的事情,即获取 user_id,以便我可以将其放入 api url,但会发生此错误,这反过来又不允许我推送到 heroku。
知道这里发生了什么吗?谢谢
【问题讨论】:
标签: javascript ruby-on-rails backbone.js heroku