我在写一个backbone.js应用程序,并且遇到问题。 我的收藏不会引发事件,任何人都可以在代码下面发现问题吗?我得到了渲染反馈,初始化器反馈......但append方法从未被调用过。我知道“../app”返回一个包含tro json项目的列表。我甚至可以看到这些是在收集中创建的。 为什么我的活动没有被叫?backbone.js不会触发我的事件
window.TablesInspectorView = Backbone.View.extend({
tagName: "div",
initialize: function() {
console.log('Initializing window.TablesInspectorView');
// setup the tables
this.data = new Backbone.Collection();
this.data.url = "../app";
this.data.fetch();
// some event binds..
this.data.on("change", this.render , this);
this.data.on("add" , this.append_item, this);
},
render: function(){
console.log("render");
_.each(this.data.models, this.append_item);
},
append_item: function(item) {
console.log("appended");
}
});
当你取一个集合,你会得到一个“复位”事件,而不是“添加”。 –
在调用获取方法之前,您是否尝试过绑定事件? – Corey
@paulHoenecke:你的权利,除了'重置'事件取代'更改'..但这并没有解决问题 - 添加事件应该仍然被激发一次收集每个项目.. –