我有兩個集合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