[英]Issue with Parse Cloud Code
I've just started working in Parse by using the cloud code guide https://parse.com/docs/cloud_code_guide but stuck in averageStars project. 我刚刚开始使用云代码指南https://parse.com/docs/cloud_code_guide来进行Parse的工作,但仍停留在averageStars项目中。 This is my code:
这是我的代码:
var Review = {
"movie" : "The Matrix",
"stars" : 5
};
Parse.Cloud.define("averageStars", function(request, response) {
var query = new Parse.Query("Review");
query.equalTo("movie", request.params.movie);
query.find({
success: function(results) {
var sum = 0;
for (var i = 0; i < results.length; ++i) {
sum += results[i].get("stars");
}
response.success(sum / results.length);
},
error: function() {
response.error("movie lookup failed");
}
});
});
However, after I run the code by using command in the guide, it just returned blank {}. 但是,在使用指南中的命令运行代码之后,它只是返回了空白{}。
This is my call to cloud code: 这是我对云代码的调用:
Maou-MacBook-Pro:MyCloudCode maou$ parse deploy
Uploading source files
Finished uploading files
New release is named v22 (using Parse JavaScript SDK v1.3.4)
Maou-MacBook-Pro:MyCloudCode maou$ curl -X POST \
> -H "X-Parse-Application-Id: tnXgGeoY38YjEbAqcakncPFRkUzaBQ29v5tK1ir7" \
> -H "X-Parse-REST-API-Key: 1YVzcl0aKATUUHZITsPasP11m0VNLrdVWiisE1YB" \
> -H "Content-Type: application/json" \
> -d '{"movie":"The Matrix"}' \
> https://api.parse.com/1/functions/averageStars
{}
I would start debugging by returning some test data early. 我将通过尽早返回一些测试数据来开始调试。 for example:
例如:
start the function with: 用以下命令启动功能:
response.success(request);
to return the request data and see if the data flow works. 返回请求数据,并查看数据流是否有效。
If that works then inside the success function, return the results: 如果这样可行,则在成功函数中返回结果:
response.success(results);
... and so on until you identify what's broken. ...依此类推,直到您发现问题所在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.