【问题标题】:Parse iOS SDK + Cloud Code: Error: Object [object Object] has no method 'set'解析 iOS SDK + 云代码:错误:对象 [对象对象] 没有方法“设置”
【发布时间】:2014-08-07 16:16:12
【问题描述】:

我是第一次尝试 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。谁能帮我解释一下为什么会这样?

【问题讨论】:

    标签: javascript ios parse-platform parse-framework


    【解决方案1】:

    .find() 返回一个数组,其结果没有 add() 方法。如果您只搜索一个用户,请尝试使用返回一个对象的 .first()。

    【讨论】:

      猜你喜欢
      • 2016-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-10
      相关资源
      最近更新 更多