我是backbone.js 的新手,在给我的收藏集成功回调时遇到了一些问题。我正在覆盖 fetch 以便有一个带有参数的 url。据我了解,我应该能够在传递给 Backbone.Collection.prototype.fetch.call() 的选项中分配成功回调......但是,我的代码不起作用。Fetch 工作正常,但没有调用回调函数。
这是我的一些代码:
App.ChartController = {
load: function(userConceptId) {
App.chartPointList.fetch(userConceptId);
}
};
App.ChartPointList = Backbone.Collection.extend({
model: App.ChartPoint,
url: function() {
return '/chartpoints/' + this.userConceptId;
},
fetch: function(userConceptId, options) {
console.log("fetch chart point");
typeof(options) != 'undefined' || (options = {});
options.success = this.postProcess;
options.error = this.handleError;
this.userConceptId = userConceptId;
return Backbone.Collection.prototype.fetch.call(this, options);
},
postProcess : function (resp, status, xhr) {
console.log("postprocess"); // never gets called
/**
... whole bunch of stuff...
**/
new App.Views.ChartView({ collection: this });
},
handleError : function (resp, status, xhr) {
alert("could not load chart data!"); // also not called
}
});
知道我做错了什么吗?谢谢!