私は backbone.js が初めてで、コレクションに成功のコールバックを与える際に問題が発生しています。パラメータを含む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
}
});
私が間違っていることは何か分かりますか?ありがとう!