0

我正在尝试从服务器发布所有管理员用户

在服务器上是这样的:

Meteor.publish("users_with_roles", function (options, role) {
    //{fields: {emails: 1, profile: 1}}
    Counts.publish(this, 'numberOfUsers', Meteor.users.find({$and:[
            {'roles.tripro': {$exists: true}},
            {'roles.tripro': role}
        ]}),
        { noReady: true });

    return Meteor.users.find({
            $and:[
                    {'roles.tripro': {$exists: true}},
                    {'roles.tripro': role}
                 ]
        }, options);
});

然后在客户端,我试图订阅这个:

$meteor.autorun($scope, function() {
        $meteor.subscribe('users_with_roles', {
            limit: parseInt($scope.getReactively('perPage')),
            skip: (parseInt($scope.getReactively('page')) - 1) * parseInt($scope.getReactively('perPage')),
            sort: $scope.getReactively('sort'),
            fields: {emails: 1, profile: 1}
         },'admin').then(function() {
                $scope.usersCount = $meteor.object(Counts ,'numberOfUsers', false);
                console.log('user counter:' + $scope.usersCount.count);
                $scope.users.forEach( function (user) {
                    //    user.onClicked = function () {
                    //        //$state.go('userProfile', {userId: user._id});
                    //    };
                    console.log(user._id);
                });
            },
            function(error)
            {
                console.log(error);
            }
        );
    });


    $scope.users =  $meteor.collection(function() {
        console.log('looking for role: ' + role);
        return Meteor.users.find({}, {
            //sort : $scope.getReactively('sort')
        });
    });

但是,从日志记录来看,客户端似乎收到了所有用户,但从服务器端的日志记录来看,它确实给出了正确的结果。

我在这里想念什么?

4

1 回答 1

1

这里有几件事要考虑。

  1. 当您请求用户时,您将始终拥有“您”。因此,如果您登录的用户不是管理员,它仍会显示在集合中。

  2. 因为您正在使用$meteor.subscribe而不是$scope.$meteorSubscribe在范围被销毁时没有清除订阅,所以它可能与来自其他范围的客户端的其他订阅混合。

于 2015-10-11T00:31:06.027 回答