[英]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.