Backbone.js 未调用主干成功回调
我在获取集合后尝试调用Backbone.js 未调用主干成功回调,backbone.js,backbone-relational,Backbone.js,Backbone Relational,我在获取集合后尝试调用success回调时遇到问题。这是集合中的代码,问题是执行executeLongPolling (function() { window.StatusCollection = Backbone.Collection.extend({ longPolling : false, intervalSeconds : 20, model: Status, url: function(){ return this.project.id
success
回调时遇到问题。这是集合中的代码,问题是执行executeLongPolling
(function() {
window.StatusCollection = Backbone.Collection.extend({
longPolling : false,
intervalSeconds : 20,
model: Status,
url: function(){
return this.project.id + 'statuses/';
},
initialize : function(){
_.bindAll(this);
},
startLongPolling : function(invervalSeconds){
this.longPolling = true;
if( invervalSeconds ){
this.invervalSeconds = invervalSeconds;
}
this.executeLongPolling();
},
stopLongPolling : function(){
this.longPolling = false;
},
executeLongPolling : function(){
var that = this;
this.fetch({
success : function(collection, response, options) {
that.onFetch();
}
});
},
onFetch : function () {
if( this.longPolling ){
setTimeout(this.executeLongPolling, 1000 * this.intervalSeconds);
}
}
}); })();
令人惊讶的是,当我添加update选项时,它工作了,并且调用了.onFetch()行:
executeLongPolling : function(){
var that = this;
this.fetch({ update: true,
success : function(collection, response, options) {
that.onFetch();
}
});
},
我使用的是主干网-0.9.10。和主干-关系-0.7.0
你知道怎么了吗?谢谢 在寻找我的问题的解决方案时遇到了您的问题,在从0.9.2升级到0.9.10后,仅添加到我的集合(我不使用fetch)似乎已中断 任何人,只要看一眼你的问题,就会发现fetch在0.9.10中发生了变化 看看这些: 或者,主干关系还没有在0.9.10中完全发挥作用
能否在Backbone.sync中设置断点并逐步完成?您可能可以看到服务器返回了什么以及为什么不调用success。另外,在成功处理程序旁边添加一个错误处理程序,并查看是否发生了错误。正如Paul所说,您应该在成功处理程序之后放置一个错误处理程序。然后在那里放一个断点。我也有同样的问题,因为我的JSON响应格式不正确。