我这里有一个Parse函数,它有一个嵌套查询。在第二个查询的成功函数中,我尝试推送到'帖子的数组。 postsArray中的属性。但是,我只是得到"无法阅读财产'帖子'未定义的'在回调中。这与全局变量范围有关吗?我无法弄明白,我对javascript没有经验。
Parse.Cloud.define("getPosts", function(request, response){
Parse.Cloud.useMasterKey();
//Get all my bubbles
var postsArray = {};
var bubbles = new Array();
var query = new Parse.Query("Bubble");
query.equalTo("owner", request.user);
query.find({
success: function(results){
for(var i = 0; i < results.length; i++){
postsArray[i] = {};
postsArray[i]["bubble"] = results[i];
postsArray[i]["posts"] = {};
//bubbles[i] = results[i];
var members = results[i].get("members");
for(var j = 0; j < members.length; j++){
// posts[i]["posts"][j] = members[j];
var postQuery = new Parse.Query("Post");
//postQuery.equalTo("owner", members[j]);
//postQuery.equalTo("members", request.user);
postQuery.find({
success: function(results2){
for(var l = 0; l < results2.length; l++){
postsArray[i]["posts"].push(results2[l]);
if(l == results2.length-1){
response.success(postsArray);
}
}
},
error: function(){
response.error("Failed");
}
});
}
}
},
error: function(){
response.error("Failed");
}
});
});