我正在获取一个集合,但是我遇到了问题,因为在集合中函数解析使用另一个ajax调用。所以如果我尝试在获取行代码之后调试fetch获取的响应,但它是未定义的。< / p>
函数调用获取:
friends: function(){
var amici=new Amicizie();
var amicilist=amici.fetch();
console.log(amicilist);<---undefined,because executed before fetch
收集名为:
var obj={};
var Amicizie = Backbone.Collection.extend({
url:'https://api.parse.com/1/classes/User/',
parse: function(data) {
var cur_user=Parse.User.current().id;
$.ajax({
type: 'GET',
headers: {'X-Parse-Application-Id':'qS0KL***EM1tyhM9EEPiTS3VMk','X-Parse-REST-API-
Key':'nh3eoUo9G***JIfIt1Gm'},
url: "https://api.parse.com/1/classes/_User/?where=....",
success: function(object) {
console.log(object );
obj=object;
console.log(obj );
},
error: function(data) {
console.log("ko" );
}
});
return obj.results;
}
});
返回Amicizie;
});