我有两个问题:
var gameScore = PFObject(className: "SiteLog-\(jobName.text)")
gameScore["TypeOfWorks"] = "\(typeOfWorks.text)"
gameScore["DateAndTime"] = "\(formattedDate)"
gameScore.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
// The object has been saved.
println("sucessfully sent to parse!")
} else {
// There was a problem, check error.description
println("Error Sending to Parse = \(error)")
}
时),然后计为两个解析我帐户的请求,因为它有两个Parse查询?以下是代码:
logbookEntries
提前致谢。
答案 0 :(得分:4)
您的代码应该是:
Parse.Cloud.define("logbookEntries", function(request, response) {
//::: Query 1 :::
var firstQuery = new Parse.Query("Logbook");
var returnData = [];
firstQuery.find().then(function(firstResults) {
returnData[0] = firstResults;
var secondQuery = new Parse.Query("Logbook");
return secondQuery.find();
}).then(function(result) {
returnData[1] = result;
response.success(returnData);
}, function(error) {
response.error(error);
});
});
或者,更好的结构方式是:
Parse.Cloud.define("logbookEntries", function(request, response) {
var firstQuery = new Parse.Query("Logbook");
var secondQuery = new Parse.Query("Logbook");
var promises = [];
promises.push(firstQuery.find());
promises.push(secondQuery.find());
Parse.Promise.when(promises).then(function(result1, result2) {
var returnData = [];
returnData[1] = result1;
returnData[2] = result2;
response.success(returnData);
}, function(error) {
response.error(error);
});
}
答案 1 :(得分:0)
只是为了更新Wain的结构化代码: Promise.when在提供数组时返回数组,因此正确的代码将是
if(!value) {
array.push(0)
} else {
array.push(value)
}
[12,20,30,0,32,0,0,5]
并且因为不需要重新打包数组,所以它只是
Parse.Promise.when(promises).then(function([result1, result2]) {
See here了解更多信息。