[错误]:TypeError:无法调用未定义的方法'getUsers'

时间:2015-07-11 17:36:15

标签: javascript parse-platform cloud-code

当我从客户端应用程序运行云代码功能时出现错误:

[Error]: TypeError: Cannot call method 'getUsers' of undefined

    at main.js:26:20

    at e (Parse.js:3:8736)

    at Parse.js:3:8185

    at Array.forEach (native)

    at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:661)

    at c.extend.resolve (Parse.js:3:8136)

    at null.<anonymous> (Parse.js:3:8815)

    at e (Parse.js:3:8736)

    at Parse.js:3:9489

    at g (Parse.js:3:9226) (Code: 141, Version: 1.7.5)

在这个函数中,我想通过相互添加角色来更改两个用户ACL。

Parse.Cloud.define("addFriend", function(request, response) {
    var userToFriend = new Parse.User();
    userToFriend.id = request.params.friendId;

    var roleName = "friendsOf_" + request.user.id;
    var roleQuery = new Parse.Query("_Role");

    var friendRoleName = "friendsOf_" + userToFriend.id;
    var friendQuery = new Parse.Query("_Role");

    roleQuery.equalTo("name", roleName);
    friendQuery.equalTo("name", friendRoleName);

    roleQuery.first().then(function(role) {
        role.getUsers().add(userToFriend);
        return role.save();
    })
    .then(function() {
        friendQuery.first().then(function(friendRole) {
        //Next line gives the error
        friendRole.getUsers().add(request.user);
        return friendRole.save();
    }).then(function() {
        response.success("Success!");    
    });
});
});

0 个答案:

没有答案