我是第一次尝试 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'
这是我第一次尝试云代码。谁能帮我解释一下为什么会发生这种情况?
最佳答案
.find() 返回一个包含结果的数组,但没有方法 add()。如果您只搜索一个用户,请尝试使用返回一个对象的 .first()。
关于javascript - 解析iOS SDK+云代码: Error: Object [object Object] has no method 'set' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25187403/