将 ReactJs 道具分配给 FlowRouter
Assign ReactJs Props to FlowRouter
如何将道具从 FlowRouter 传递到我的 React 组件。那可能吗?文档太棒了。
我正在做这样的事情:
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
但数组是空的。我必须将逻辑放入反应组件中。那是正确的方法吗?我希望不会。
我认为您需要订阅...请参阅此处的文档 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;
},
});
如何将道具从 FlowRouter 传递到我的 React 组件。那可能吗?文档太棒了。
我正在做这样的事情:
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
但数组是空的。我必须将逻辑放入反应组件中。那是正确的方法吗?我希望不会。
我认为您需要订阅...请参阅此处的文档 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;
},
});