简体   繁体   English

如何在meteor.js中访问集合的元素?

[英]How to access elements of the collection in meteor.js?

I apologize for such a simple question, but documentation meteor.js very briefly, many of the points are not described in great detail. 对于这个简单的问题,我深表歉意,但是非常简短地介绍了meteor.js文档,其中许多要点并未详细描述。 How to access the elements of the collection in the meteor? 如何访问流星中的集合元素? Suppose there is a built collection of User , which stores user data. 假设有一个内置的User集合,用于存储用户数据。 The user ID can be obtained by applying the following code on the client side: 可以通过在客户端应用以下代码来获取用户ID:

return Meteor.userId()

However, but if you want to display other data (username, email), it is already a problem. 但是,但是如果您要显示其他数据(用户名,电子邮件),则已经存在问题。 After about such code issued inscription [object Object] : 在大约这样的代码之后发出题词[object Object]

return Meteor.users.find({emails:"geckt@rambler.ru"})

What is the correct syntax to access elements of the collection that I have missed? 访问我错过的集合中的元素的正确语法是什么?

If you want to display data from person who is logged in you have Meteor.user() object where all values are hidden, use it like : Meteor.user().username or so, for person who isn't logged but you have her username for example 如果要显示来自登录用户的数据,则可以使用Meteor.user()对象隐藏所有值,请使用它: Meteor.user().username左右,对于未登录的用户但您拥有例如她的用户名

Meteor.users.findOne({username:<username>}).some_data

or 要么

Meteor.users.find({username:<username>}).fetch()[0].some_data

Of course first one is better to use 当然第一个更好用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM