私のバックボーン関数では、データをsetTimout
取得している間、データを取得し続けています。プロパティを送信している{add:true}
ため、コレクションにモデルが追加されたときに、新しく取得したモデルが既存のコレクションに追加されます。add
メソッドをトリガーする必要があります。
しかし、コレクションで作成された追加プロセスの後、トリガーが得られません。ビュープロセスでデータを取得していますが、正しくありません。
私のコレクション:
list.collect = Backbone.Collection.extend({
model:list.model,
url : 'data/names.json',
initialize:function(){
this.fetch({success:this.prompter});
this.on("add", this.addOne, this);//it should get triggered while added the model
},
addOne:function(e){
console.log('addone'); // the method not called
}
});
私の見解 :
list.view = Backbone.View.extend({
initialize:function(){
this.collection = new list.collect();
var that = this;
var updateData = function(){
that.collection.fetch({add:true}); // i am passing add:true!
myTimeout = setTimeout(updateData,10000)
}
var myTimeout = setTimeout(updateData,10000)
this.collection.on("reset", this.render, this);
},
render:function(data){
_.each(this.collection.models, function(data){
//console.log(data.get('name'));
})
}
});
問題について何か考えはありますか?