0

如何将道具从FlowRouter 传递给我的反应组件。那可能吗?文档很棒。

我在做这样的事情:

FlowRouter.route('/dashboard', {
  name: 'dashboard',
  action(){
    var x = Projects.find().fetch(); // this not working
    console.log(x); // x is []. Why?
    ReactLayout.render(App, {
      nav: <Nav />,
    content: <Profile data={x}/>
    });
  }
});

在我的应用程序中,我想说this.props.data但数组是空的。我必须将逻辑放入反应组件中。这是正确的方法吗?我希望不是。

4

1 回答 1

0

我认为您需要订阅...请参阅此处的文档https://github.com/kadirahq/flow-router#subscription-management

FlowRouter.route('/dashboard', {
  name: 'dashboard',
  subscriptions(){
      this.register('myProjects', Meteor.subscribe('projects'));
  },
  action(){
    ReactLayout.render(App, {
      nav: <Nav />,
      content: <Profile data={myProjects}/>
    });
  }
});

但经过进一步审查,他们实际上建议您确实在 React 组件中获取流星数据......请参阅此处的文档

https://kadira.io/academy/meteor-routing-guide/content/subscriptions-and-data-management/with-react

  Profile = React.createClass({
     mixins: [ReactMeteorData],
     getMeteorData() {
       var data = {};
       var handle = Meteor.subscribe('projects');
       if(handle.ready()) {
         data.projects = Projects.find({});
       }
       return data;
     },    
  });

示例项目:https ://github.com/aaronksaunders/meteor-react-demo2

于 2016-01-04T14:54:43.080 回答