I run the hello job but the Select function return empty value.
我运行hello作业,但Select函数返回空值。
I call the Select function by use Parse.Cloud.define
and the result has value.
我通过使用Parse.Cloud.define调用Select函数,结果有值。
And the Query.find
in hello job has value.
并且hello作业中的Query.find具有值。
Please help me to figure it out.
请帮我解决一下。
Parse.Cloud.job("hello", function(request, status) {
var Query = new Parse.Query("yee");
Query.equalTo("PushTime", NowTime);
Query.find({
success: function(results) {
for (var i = 0; i < results.length; i++) {
var tp = results[i];
alert("a");
var mresult = Select(tp.get("ID"));
alert("aa" + mresult);
if (mresult != "error" || mresult != "undefined") {
InstallationQuer = new Parse.Query(Parse.Installation);
InstallationQuer.equalTo("NO", tp.get("No"));
Parse.Push.send({
where: InstallationQuer,
data: {
alert: mresult
}
});
} else {
console.error("error");
status.error("error");
}
}
console.log("success promise!!")
status.success("success promise!!");
},
error: function(error) {
console.error("Promise Error: " + error.message);
status.error("error");
}
});
});
function Select(ID) {
var a = "";
var Query = new Parse.Query("Meeting");
alert(ID);
Query.equalTo("ID", ID);
Query.find({
success: function(results) {
for (var i = 0; i < results.length; i++) {
a = results[i].get("Details");
}
return a;
},
error: function(error) {
return "error";
}
});}
1 个解决方案
#1
0
You call Select
function synchronously, therefore it returns before Query.find
gets any chance to finish as it is an asynchronous function. Make your function return a Promise
instead and wait for that promise to be fulfilled before processing the results further.
你同步调用Select函数,因此它在Query.find有机会完成之前返回,因为它是一个异步函数。让您的函数返回Promise,并在进一步处理结果之前等待该promise。
#1
0
You call Select
function synchronously, therefore it returns before Query.find
gets any chance to finish as it is an asynchronous function. Make your function return a Promise
instead and wait for that promise to be fulfilled before processing the results further.
你同步调用Select函数,因此它在Query.find有机会完成之前返回,因为它是一个异步函数。让您的函数返回Promise,并在进一步处理结果之前等待该promise。