我正在尝试从服务器发布所有管理员用户
服务器上的是这样的:
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')
});
});
但是,从日志记录开始,客户端似乎收到了所有用户,但从服务器端登录,它确实给出了正确的结果。
我在这里缺少什么?
答案 0 :(得分:1)
这里要考虑几件事。
当您请求用户时,您将始终拥有“您”。因此,如果您登录的用户不是管理员,它仍会显示在集合中。
因为您使用的是$meteor.subscribe
而不是$scope.$meteorSubscribe
,所以当范围被销毁时您没有清除订阅,因此它可能与其他范围的客户端上的其他订阅混合在一起。