Backbone.js 不要开枪
我已经设置了一个简单的backbone.js应用程序。除了一个特别的事件外,一切都在运转 不工作的部分是“this.listenTo”类型的事件。我以前从未使用过这种类型的事件,所以我确信这是我的一些误解 app.js:Backbone.js 不要开枪,backbone.js,Backbone.js,我已经设置了一个简单的backbone.js应用程序。除了一个特别的事件外,一切都在运转 不工作的部分是“this.listenTo”类型的事件。我以前从未使用过这种类型的事件,所以我确信这是我的一些误解 app.js: new bookView({ model: bookModel }).render(); bookModel.js: Backbone.Model.extend({ defaults: function() { return { sec
new bookView({
model: bookModel
}).render();
bookModel.js:
Backbone.Model.extend({
defaults: function() {
return { sections: new SectionCollection()
}
});
|
bookView.js:这就是事件不触发的地方
return Backbone.View.extend({
initialize: function() {
this.sections = this.model.get('sections');
this.listenTo(this.sections, 'add', this.addSection);
},
addSection: function() {
//never gets here....
console.log("adding section...");
}
});
有什么建议吗
谢谢 代码正常,要触发事件,必须执行以下操作:
view.sections.add({
name: "name"
...
});
您的图书模型
return{sections:new SectionCollection()}
中缺少一个}