我有两个集合 People 和 Teams。
如果有人添加到“人员”集合中,我希望 Teams 集合能够收听。
但是,我不断收到此错误: Uncaught TypeError: Cannot read property '_listenerId' of undefined
也许我误解了 bind 和 listenTo 的概念?下面是我用于这两个集合的代码。
var People = Backbone.Collection.extend({
url: '/people',
model: Person,
comparator: 'id',
initialize: function() {
//Why does this return '_listenerID of undefined'
this.bind('add', function() {
var teams = new Teams;
teams.render;
});
},
});
var Teams = Backbone.Collection.extend({
url: '/team',
model: Team,
comparator: 'id',
initialize: function() {
this.listenTo(People.collection, 'add', this.render);
},
render: function() {
console.log("POOP")
}
});