我有两个集合People and Teams。主干听众事件不起作用
我希望Teams集合可以侦听是否有人添加到People集合中。
不过,我不断收到此错误: 遗漏的类型错误:无法读取属性“_listenerId”的未定义
也许我误解绑定和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")
}
});
'console.log(“POOP”)'我以为我是唯一一个... – Trip