Search code examples
jquerybackbone.js

callback in when/done never getting called


In situations where there are no entries in either of my collections, the render function never got called. Question: What is the bare minimum that needs to be returned for a jQuery when/done to resolve?

$.when(collection2.fetch(), collection2.fetch())
    .done(function(data, data2){
        ...
        _this.render();
    });

Note, I tagged this question with Backbone.js to indicate that the fetch request is a Backbone.Collection.fetch().


Solution

  • Without your code for fetch, I can only suggest the minimum.

    If your collection is empty, return $.Deferred().resolve().promise() from fetch() and it run done immediately (immediately upon both promises being resolved of course)