流星&account-base - 如何获取不同用户的数据 [英] Meteor & account-base - how to get data for different users

查看:50
本文介绍了流星&account-base - 如何获取不同用户的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从 Meteor-admin 存根创建的 Meteor 基本项目:(https://github.com/yogiben/meteor-admin)

I have basic project in Meteor created from Meteor-admin stub: (https://github.com/yogiben/meteor-admin)

我需要为所有用户显示头像,而不仅仅是当前用户.为了显示用户的头像,我需要他的电子邮件地址.(我正在使用实用程序:avatar https://atmospherejs.com/utilities/avatar)

I need to display avatars for all users, not only current one. For displaying user's avatar I need his email address. (I am using utilities:avatar https://atmospherejs.com/utilities/avatar)

问题:我应该对项目进行哪些调整才能访问其他用户的数据?

Question: what adjustments to project should I make to be able to access other users' data?

可能与发布用户有关.

目前我有:

{{> avatar user=getAuthor shape="circle" size="small"}}         

getAuthor: ->
  console.log 'Owner:'
  console.log @owner
  user = Meteor.users.findOne(@owner)
  console.log user
  user

这会为所有用户正确打印 Owner: @owner (id),但仅为当前用户填充 user 对象.

This correctly prints Owner: @owner (id) for all users, but user object is only populated for current user.

我在服务器端也有这个代码:

I also have this code in server-side:

Meteor.publishComposite 'user', ->
  find: ->
    Meteor.users.find _id: @userId
  children: [
    find: (user) ->
      _id = user.profile?.picture or null
      ProfilePictures.find _id: _id
    ]

(儿童/个人资料图片无关紧要)

(children / ProfilePicture are irrelevent)

我认为 account-base 库会关闭发布功能还是什么?感谢帮助!

I think account-base library turns publishing off or something? Thanks for help!

额外问题:我只想访问有关用户的一些信息(电子邮件地址).

Bonus question: I would like to access only some info about an user (email address).

推荐答案

如果删除包 autopublish,则需要明确指定服务器向客户端发送的内容.你可以通过 Meteor.publishMeteor.subscribe 来做到这一点.

If you remove the package autopublish, you need to specify explicitly what the server sends to the client. You can do this via Meteor.publish and Meteor.subscribe.

例如,要发布您可以执行的所有用户的电子邮件地址:

For instance, to publish the email addresses of all users you could do:

if (Meteor.isServer) {
    Meteor.publish('emailAddresses', function() {
        return Meteor.users.find({}, {
            fields: {
                'email': 1
            }
        });
    });
}

之后,您需要订阅客户端上的发布:

After that, you need to subscribe to the publication on the client:

if (Meteor.isClient) {
    Meteor.subscribe("emailAddresses");
}

详细了解Meteor 的发布和订阅功能.

这篇关于流星&account-base - 如何获取不同用户的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆