backbone.js - Backbone fetch success callback -
i'm new backbone.js , i'm having issues giving collection success callback. i'm overriding fetch in order have url parameter in it. understand should able assign success callback in options pass backbone.collection.prototype.fetch.call()... but, code isn't working. fetch works correctly, callback function not called.
here bit of code:
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: }); }, handleerror : function (resp, status, xhr) { alert("could not load chart data!"); // not called } }); any idea i'm doing wrong? thanks!
@fguillen's comment , another thread helped me figure out. specifically:
collection.fetch() call reset() on success, in turn trigger 'reset' event. subscribers collections reset event should receive event.
the issue wasn't success callback @ all. turns out had problem in view subscribed chartpointlist reset event. function in view being called before success callback , throwing error, , success callback not being called.
Comments
Post a Comment