我是第一次尝试 Cloud Code,但遇到了一些麻烦。我认为我拥有大部分权利。我正在尝试将用户的“ID”添加到名为“likes”的数组中的另一个用户对象。我正在使用的代码是...
Parse.Cloud.define("lifeLike", function(request, response) {
var userID = request.params.userID;
var selectedFriendID = request.params.selectedFriendID;
var query = new Parse.Query(Parse.User);
query.equalTo("userID", selectedFriendID);
query.find().then(function (users) {
Parse.Cloud.useMasterKey();
users.add("likes", userID);
users.save().then(function(user) {
response.success(user);
}, function(error) {
response.error(error)
});
}, function (error) {
response.error(error);
});
});
当我在 iOS 中调用它时
[PFCloud callFunctionInBackground:@"like" withParameters:
@ {
@"userID": [PFUser currentUser][@"userID"],
@"selectedFriendID": self.selectedFriendID
}
block:^(id object, NSError *error) {
if (error) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:[NSString stringWithFormat:@"Unable to like this user.\n%@", [error userInfo][@"error"]] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Liked" message:@"You now like this user." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
}];
我得到这个错误
Error: TypeError: Object [object Object] has no method 'add'
这是我第一次尝试 Cloud Code。任何人都可以帮我解决为什么会这样吗?