A bit new to JS. I'm using Parse.com's CloudCode in order to calculate the "score" of a "Post" instance. I retrieve any "Votes" associated with a post, and then sum up their "value", then return that value.
Parse.Cloud.define("postScore", function(request, response) {
var postId = request.params.postId;
var post = Parse.Object.extend("Post");
post.id = postId;
var query = new Parse.Query("Vote");
query.equalTo("post", post);
query.find({
success: function(results) {
var sum = 0;
for (var i = 0; i < results.length; ++i) {
sum += results[i].get("value");
}
response.success(sum);
},
error: function() {
response.error("Could not calculate value");
}
});
});
Getting this error:
2014-05-02 19:21:09.124 XXX[33361:2d3b] Error: undefined (Code: 141, Version: 1.2.19)
Not too sure what the issue is.
Calling it in my iOS app like so:
- (void)fetchPostScores
{
for (BVYPost *post in _postsArray) {
[PFCloud callFunctionInBackground:@"postScore" withParameters:@{@"postId": post.objectId} block:^(NSNumber *score, NSError *error) {
if (!error) {
post.score = score;
}
}];
}
}
This is wrong:
var post = Parse.Object.extend("Post");
post.id = postId;
The correct syntax would be:
var post = new Parse.Object("Post");
post.id = postId;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.