Why the Backbone Collection does not return a promise

The following code example works well:

Auth_controller.prototype.isLogged = function(){ 
    //Check if the user is authenticated 
    var getAuthStatus = this.auth_model.fetch(); 
    return getAuthStatus; 
}; 

Auth_controller.prototype.redirect = function(fragment, args, next){ 

    var getAuthStatus = this.isLogged(); 
    var self = this; 

    $.when(getAuthStatus).then(function(response){ 
        //Do something with the response 
    }
}); 

This does not seem to work for the collection. When I register a collection with the console, I get an empty collection.

I know that I can use the success callback function from a method (already tested), but I don't want to do this because I want the function to return a promise that I can call from other functions: good.
Edit -> No, I'm sorry that it does not work in the callback with success either as it seems.

Any suggestions on a workaround?

Change

, .
- , , , .
, , , , .

enter image description here

Edit2:

:

define([
  /*--- libraries ---*/
  'jquery',     
  'underscore', 
  'backbone', 

  /*--- model ---*/
  'models/users/role_model'

], function($, _, Backbone, 
                Role_model){

    var Role_collection = Backbone.Collection.extend({ 
        url: '/ingeb/api_v1/users/roles', 
        model: Role_model 
    }); 

    return Role_collection; 

}); 
+4

Source: https://habr.com/ru/post/1535767/


All Articles