[英]Binding Reset In Backbone.js
我正在嘗試在ribs.js中進行簡單的收集,但是我不明白為什么未調用我的回調函數(在bind中指定)。 據我了解的文檔,當我執行fetch()時,應該觸發reset事件。 有什么建議么? (代碼在下面)。
Customer = Backbone.Model.extend(
);
CustomerList = Backbone.Collection.extend({
model : Customer,
url : "test.php",
});
var ChartView = Backbone.View.extend({
el: $('body'),
initialize: function(){
_.bindAll(this, 'render');
this.collection.bind("reset", self.render);
this.collection.fetch(
);
},
render : function() {
console.log("render");
}
});
var chartView = new ChartView( { collection: new CustomerList()} );
})(jQuery);
如果使用骨干1.0.0,則應傳遞reset:true
進行重置。 否則,它只會將模型set
為以前update
的集合
this.collection.fetch({reset:true});
確保來自網址的響應是有效的json。 只有在成功時才會觸發reset
事件。
看一下這個。 就像@nikoshr在https://stackoverflow.com/a/16538588/1211174上說的那樣。 有同步事件。 因此,每次您可以捕獲同步時,都強迫主干重置該集合
https://github.com/backbone-paginator/backbone.paginator/issues/164
this.collection.bind("sync", function(){
console.log('got sync');
this.render(){, this );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.