显示Meteor React Client中的所有用户

我有一些麻烦让所有注册用户显示在客户端。 std:accounts-ui包包含在.meteor/packagesautopublish包已被删除。

所有用户的数据都作为allUsersUsers.jsallUsers ,而客户端从react-meteor-data提供的createContainer订阅allUsers发布。

但是,页面只呈现当前login的用户的详细信息Meteor.users().find().fetch()在浏览器中运行Meteor.users().find().fetch()只显示当前login的用户,如果用户是未login。

在服务器端运行console.log(Meteor.users.find().fetch()正确输出所有用户。

为什么在浏览器上发生这种情况?

/imports/api/Users.js

 import { Meteor } from 'meteor/meteor'; if (Meteor.isServer) { Meteor.publish('allUsers', function() { return Meteor.users.find({}); }) } 

/imports/ui/App.jsx

 import React, { Component, PropTypes } from 'react'; import { createContainer } from 'meteor/react-meteor-data'; import { Accounts } from 'meteor/std:accounts-ui'; import { Table } from 'react-bootstrap'; import User from './User'; export class App extends Component { renderUsers() { return this.props.users.map((user) => ( <User key={user._id} user={user} /> )); } render() { return ( <div> <h1>Users</h1> <Table> <tbody> <tr> <td>ID</td> <td>Email</td> <td>createdAt</td> </tr> { this.renderUsers() } </tbody> </Table> </div> ) } } App.propTypes = { users: PropTypes.array.isRequired } export default createContainer(() => { Meteor.subscribe('allUsers'); return { users: Meteor.users.find().fetch() } }, App); 

/imports/ui/User.jsx

 import React, { Component } from 'react'; export default class Users extends Component { render() { return ( <tr> <td>{ this.props.user._id}</td> <td>{ _.get(this.props, 'user.emails[0].address', 'UNKNOWN') }</td> <td>{ this.props.user.createdAt }</td> </tr> ) } } 

当我使用angular2和meteor时,我遇到了同样的问题。 我也尝试使用Meteor.users.find({});访问数据Meteor.users.find({});

但是这不是正确的使用方法。 首先使用这个,你应该创build一个像这样的新集合

 export const Users = MongoObservable.fromExisting(Meteor.users);<-- most important line 

然后进入

 Meteor.publish("userData", function() { if (Roles.userIsInRole(this.userId, 'admin')) { return Meteor.users.find(); } else { const selector = { '_id': this.userId }; return Meteor.users.find(selector); } }); 

并通过订阅来在你的文件中使用。

 MeteorObservable.subscribe('userData').subscribe(() => { this.userlist=Users.find({}); }); 

我做了angular2.您使用最后一个订阅部分的反应语法。