[英]Binding Reset In Backbone.js
I'm trying to do a simple collection in backbone.js, but I don't understand why my callback function (specified in bind) isn't being called. 我正在尝试在ribs.js中进行简单的收集,但是我不明白为什么未调用我的回调函数(在bind中指定)。 From what I understand from the documentation, when I do a fetch(), the reset event should be triggered. 据我了解的文档,当我执行fetch()时,应该触发reset事件。 Any suggestions? 有什么建议么? (Code is below). (代码在下面)。
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);
If you are using backbone 1.0.0 you should be passing reset:true
to reset. 如果使用骨干1.0.0,则应传递reset:true
进行重置。 Else it will just set
the models to the collection which was the erstwhile update
否则,它只会将模型set
为以前update
的集合
this.collection.fetch({reset:true});
Ensure the response from the url is a valid json. 确保来自网址的响应是有效的json。 reset
event will be fired only on success. 只有在成功时才会触发reset
事件。
check this out. 看一下这个。 like @nikoshr said on https://stackoverflow.com/a/16538588/1211174 . 就像@nikoshr在https://stackoverflow.com/a/16538588/1211174上说的那样。 there is sync event. 有同步事件。 so instead forcing backbone to reset the collection each time you can catch the sync 因此,每次您可以捕获同步时,都强迫主干重置该集合
https://github.com/backbone-paginator/backbone.paginator/issues/164 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.