Javascript 代码141解析云代码嵌套查询时未调用成功/错误消息
我一直收到代码141错误成功/未调用错误。我正在运行另一个函数getCinemasInLocation,它返回类似于{result:[result1,result2]}的JSON。我希望迭代这个数组,并在每次循环运行时运行一个查询,并将所有结果添加到一个数组中。也就是说,所有操作的结果都将在一个数组中。我做得对吗Javascript 代码141解析云代码嵌套查询时未调用成功/错误消息,javascript,json,parse-platform,cloud,parse-cloud-code,Javascript,Json,Parse Platform,Cloud,Parse Cloud Code,我一直收到代码141错误成功/未调用错误。我正在运行另一个函数getCinemasInLocation,它返回类似于{result:[result1,result2]}的JSON。我希望迭代这个数组,并在每次循环运行时运行一个查询,并将所有结果添加到一个数组中。也就是说,所有操作的结果都将在一个数组中。我做得对吗 //This function uses getCinemasInLocation to retrieve the movie objects that are showing in
//This function uses getCinemasInLocation to retrieve the movie objects that are showing in the cinemas
Parse.Cloud.define("getMovieIdsInCinemas", function(request, response) {
var cinemasInLocaton = [];
var theLocation = request.params.theLocation;
cinemasInLocation = Parse.Cloud.run("getCinemasInLocation", {theLocation: theLocation});
for (i = 0; i < cinemasInLocation.length; i++){
var query = new Parse.Query("showing");
var movieIds = [];
query.equalTo("cinema", {
__type: "Pointer",
className: "Cinema",
objectId: cinemasInLocation[i]
});
query.find({
success: function(results) {
for (var i = 0; i < results.length; i++) {
movieIds.push(results[i].get("movie"));
}
response.success(movieIds);
},
error: function() {
response.error("movie lookup failed 2");
}
});
}
});
//此函数使用getCinemasInLocation检索电影院中显示的电影对象
定义(“getMovieIdsInCinemas”,函数(请求、响应){
var cinemasInLocaton=[];
var theLocation=request.params.theLocation;
cinemasInLocation=Parse.Cloud.run(“getCinemasInLocation”,{theLocation:theLocation});
对于(i=0;i
这是无法工作的getCinemasInLocation
function getCinemasInLocation(theLocation) {
// some code
//var result = ["xiUXXYFhAl","Yanh9iDykk"];
//return result;
var result = new Parse.Promise();
var query = new Parse.Query("Cinema");
query.equalTo("Location", theLocation);
query.find({
success: function(objects) {
var cinemas = [];
for (var i = 0; i < objects.length; i++) {
var cinema = objects[i];
cinemas.push(cinema.id);
}
result.resolve(cinemas);
},
error: function(error) {
result.reject(error);
}
});
return result;
}
函数getCinemasInLocation(位置){
//一些代码
//var结果=[“xuxxyfal”,“Yanh9iDykk”];
//返回结果;
var result=new Parse.Promise();
var query=newparse.query(“电影院”);
query.equalTo(“位置”,位置);
查询.查找({
成功:功能(对象){
var cinemas=[];
对于(var i=0;i
var\=require('下划线')
函数getCinemasInLocation(位置){
//一些代码
var结果=[id1,id2];
返回结果;
}
//此函数用于返回电影院的电影ID数组
函数getMovieIdsInCinema(cinemaId){
var result=new Parse.Promise();
var query=newparse.query(“显示”);
query.equalTo(“电影院”{
__键入:“指针”,
类名:“电影院”,
对象:cinemaId
});
查询.查找({
成功:功能(对象){
var movieIds=[];
对于(var i=0;i
非常感谢。它工作得很好。我编辑了getCinemasinLocation函数以从数据库中检索电影院,然后它返回一个空数组。我将张贴上面的编辑。我复制了getMovieIdsInCinema(),但它仍然不起作用
var _ = require('underscore');
function getCinemasInLocation(theLocation) {
// some code
var result = [id1, id2];
return result;
}
// This function returns the array of movieIds of a cinema
function getMovieIdsInCinema(cinemaId) {
var result = new Parse.Promise();
var query = new Parse.Query("showing");
query.equalTo("cinema", {
__type: "Pointer",
className: "Cinema",
objectId: cinemaId
});
query.find({
success: function(objects) {
var movieIds = [];
for (var i = 0; i < objects.length; i++) {
var movie = objects[i].get("movie");
movieIds.push(movie.id);
}
result.resolve(movieIds);
},
error: function(error) {
result.reject(error);
}
});
return result;
}
Parse.Cloud.define("getMovieIdsInCinemas", function(request, response) {
var cinemasInLocation = [];
var theLocation = request.params.theLocation;
cinemasInLocation = getCinemasInLocation(theLocation);
var promises = [];
_.each(cinemasInLocation, function(cinemaId) {
promises.push(getMovieIdsInCinema(cinemaId));
});
Parse.Promise.when(promises).then(
function() {
var result = [];
_.each(arguments, function(object) {
result.push(object); // each object is an array of movieIds
});
response.success(result); // return array of arrays
},
function(error) {
response.error(error);
}
);
});