返回除当前用户之外的所有流星用户
Return All Meteor Users Except The Current User?
我有一个显示所有注册用户的页面,但想省略当前用户。有没有办法返回除当前用户之外的所有流星用户。
这是我的网页:
<template name="users">
<div class="contentDiv">
<div class="blueTop pageContent" id="profileName">Users</div>
{{#each users}}
<div class="pageContent text">
<a class="user link" id="{{_id}}">{{profile.firstName}} {{profile.lastName}}</a>
<button class="addFriend">Add Friend</button>
</div>
{{/each}}
</div>
</div>
</template>
还有我的JavaScript:
if (Meteor.isClient) {
Meteor.subscribe("users");
Template.users.helpers({
users:function(){
return Meteor.users.find({}, {sort: {firstName: -1}}).fetch();
}
});
}
if (Meteor.isServer) {
Meteor.publish("users",function(){
return Meteor.users.find();
});
}
您可以使用
比较查询运算符$ne
过滤掉不等于指定值的文档,在您的情况下Meteor.userId()
。
例如:
Meteor.users.find({_id: {$ne: Meteor.userId()}});
如果您使用的是出版物,则只需使用 $ne 运算符即可。 this.userId
在所有发布功能上设置为当前用户。
Meteor.publish('all_users', function () {
return Meteor.users.find({
_id: { $ne: this.userId }
});
});
相关文章:
- 我怎么能让流星简单模式中的一个字段等于一个js变量,并且仍然让用户填写简单模式的其余部分
- 用户登录时的流星事件
- 流星用户帐户和alanning流星角色-登录时检查角色
- 流星 - 添加带有熨斗的路由后无法提交用户.路由器到登录和注册表单
- 流星js中没有服务的用户身份验证
- 流星出版物和订阅用户组
- 流星用户帐户 - 内部状态
- 返回除当前用户之外的所有流星用户
- 流星.js添加有关用户帐户注册的更多信息
- 流星:在不注销的情况下更改用户密码
- MeteorJS用户帐户:核心和流星角色
- 获取客户端流星上的多个用户数据
- 流星 - 允许多个用户编辑一个帖子
- 执行流星重置时,登录用户的应用程序页面冻结
- 流星:如何获取用户帐户包以将新的用户文档写入远程集合
- 用户登录后流星重新渲染模板
- 访问数据时未定义流星用户
- 流星:检查用户是否阅读了消息
- 是否可以在不使用帐户密码包的情况下获取流星用户ID
- 流星用户助手在更新后挂起