fetch method on collection not returning deferred object
mikeymckay opened this issue · comments
I expected to get a jquery deferred object back when I call fetch on a collection - but I am getting undefined. This means I can't hook up a complete callback.
var deferred = myCollection.fetch()
deferred.complete(function(){console.log("success or error have been completed")})
The Backbone Collection does not return a deferred object iirc. You need to pass an object as the first parameter to get called back when the fetch has finished.
myCollection.fetch({
success: function(){},
error: function(){}
})
Also the Collection fires a "reset"-event when it's done loading the new models.
Does that answer your question?
That definitely helps. So for fetches done on the collection if I want to
replicate the "complete" callback I need to add the code I want to be
called to both success and error?
complete = function(){console.log("Fetching has either succeeded or failed)}
myCollection.fetch({
success: function(){complete()},
error: function(){complete()}
})
I was hoping to be able to do:
myCollection.fetch({
complete: function(){complete()},
})
or using the "new" deferred stuff in jquery
deferred = myCollection.fetch()
deferred.complete(complete)
or via the new deferred approach:
On Tue, Jan 10, 2012 at 3:40 PM, Jan Monschke <
reply@reply.github.com
wrote:
Does that answer your question?
Reply to this email directly or view it on GitHub:
Unfortunately yes, because jquery.couch.js overwrites the complete-handler.
But I'm working on a fix. Will post it in some minutes, stay tuned.
I now manually call complete for each method. That works around the problem.
Great! That's what I ended up doing in my code. Thanks for working on this
great library and for being responsive. :-)
On Tue, Jan 10, 2012 at 4:27 PM, Jan Monschke <
reply@reply.github.com
wrote:
I now manually call complete for each method. That works around the
problem.
Reply to this email directly or view it on GitHub: