下面的示例代码运行良好:
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
}
});
但这似乎不适用于集合。
当我控制台记录集合时,我得到一个空集合。
我知道我可以在方法中使用成功回调函数(已经测试过),但我不想这样做,因为我希望该函数返回一个我也可以从其他函数调用的承诺。
Edit-> 不,抱歉,看起来它在成功回调中也不起作用。
对于解决方法有什么建议吗?
Edit;
此图显示了从模型和集合获取方法返回的内容。
除非我做了一些明显的错误,否则我不明白为什么会发生这种情况。
当控制台在成功回调中记录返回的响应时,我看到屏幕截图中所示的空对象被填充。
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;
});