Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 无法使用流路由器/React在Meteor中订阅React组件内的追随者_Mongodb_Meteor_Reactjs_Flow Router - Fatal编程技术网

Mongodb 无法使用流路由器/React在Meteor中订阅React组件内的追随者

Mongodb 无法使用流路由器/React在Meteor中订阅React组件内的追随者,mongodb,meteor,reactjs,flow-router,Mongodb,Meteor,Reactjs,Flow Router,问题: 我无法使用Flow Router+React获得用户的追随者,在React组件内部订阅 我用流星,流路由器,反应。我想订阅追随者, 但当我运行应用程序时,它总是返回空。我不确定出了什么问题 我遵循这种方法:订阅Arunoda的内部React组件 当我使用mongo shell检查查询时,它可以工作: (即返回其id为“5MJJPc78W3ipXpWzy”的Alice的追随者(1个用户,Bob) y代码如下: lib/router FlowRouter.route('/users/:use

问题: 我无法使用Flow Router+React获得用户的追随者,在React组件内部订阅

我用流星,流路由器,反应。我想订阅追随者, 但当我运行应用程序时,它总是返回空。我不确定出了什么问题

我遵循这种方法:订阅Arunoda的内部React组件

当我使用mongo shell检查查询时,它可以工作: (即返回其id为“5MJJPc78W3ipXpWzy”的Alice的追随者(1个用户,Bob)

y代码如下:

lib/router

FlowRouter.route('/users/:userid/followers', {
  name: 'followers',
  action(params) {
    ReactLayout.render(MainLayout, {
      content: <FollowersBox {...params}/>
    });
  }
});
客户端/组件/配置文件/FollowersBox

FollowersBox = React.createClass({
  mixins: [ReactMeteorData],

  getMeteorData() {
    let data = {};
    let followersSubs = Meteor.subscribe('followers', this.props.userid); // Always empty!

    if(followersSubs.ready()) { // Never be ready
      data.followers = Meteor.users.find({followings: this.props.userid}).fetch();
    }
    return data;
  },

  render(){
    let followersList = "";
    if(this.data.followers){
      followersList = this.data.followers.map((user)=> {
        return <UserItem
              key={user._id}
              userId={user._id}
              username={user.username}
              />
      });
    } 

    return (
      <div>
        <h4>Followers</h4>
        <ul>
          {followersList}
        </ul>
      </div>
    )
  }
});
FollowersBox=React.createClass({
mixins:[数据],
getMeteorData(){
让数据={};
让followersSubs=Meteor.subscribe('followers',this.props.userid);//始终为空!
如果(followersSubs.ready()){//永远不要准备好
data.followers=Meteor.users.find({followers:this.props.userid}).fetch();
}
返回数据;
},
render(){
让followersList=“”;
if(this.data.followers){
followersList=this.data.followers.map((用户)=>{
返回
});
} 
返回(
追随者
    {followersList}
) } });
全面回购
发布函数应返回光标:

Meteor.publish('followers', (userId) => {
  check(userId, String);

  return Meteor.users.find({followings: userId});
});

哦,天哪,这是个容易犯的错误!非常感谢。
FollowersBox = React.createClass({
  mixins: [ReactMeteorData],

  getMeteorData() {
    let data = {};
    let followersSubs = Meteor.subscribe('followers', this.props.userid); // Always empty!

    if(followersSubs.ready()) { // Never be ready
      data.followers = Meteor.users.find({followings: this.props.userid}).fetch();
    }
    return data;
  },

  render(){
    let followersList = "";
    if(this.data.followers){
      followersList = this.data.followers.map((user)=> {
        return <UserItem
              key={user._id}
              userId={user._id}
              username={user.username}
              />
      });
    } 

    return (
      <div>
        <h4>Followers</h4>
        <ul>
          {followersList}
        </ul>
      </div>
    )
  }
});
Meteor.publish('followers', (userId) => {
  check(userId, String);

  return Meteor.users.find({followings: userId});
});