问题:我不能让用户的追随者使用Flow-路由器+ React,订阅内部React组件。
我用流星,流动路由器,反应。我正在尝试订阅追随者,但当我运行这个应用程序时,它总是返回为空。我不知道是怎么回事。
我遵循这样的方法:通过Arunoda订阅inside React组件
当我使用mongo检查查询时,它起作用了:(即返回_id为“5MJJPC78W3ipXpWzy”的爱丽丝的追随者(1名用户,Bob) )。
meteor:PRIMARY> db.users.find({followings: "5MJJPc78W3ipXpWzy"}).pretty()
{
"_id" : "v2Kikp8Wa5FSJi64b",
"createdAt" : ISODate("2015-12-11T11:08:50.209Z"),
"services" : {
"password" : {
"bcrypt" : "$2a$10$IzfXjbXlYw4BuTMLroSjaOmgqnj8Z9sWXc4uyvHuXurirWRgDcZJ2"
},
"resume" : {
"loginTokens" : [
{
"when" : ISODate("2015-12-11T11:08:50.213Z"),
"hashedToken" : "jN0jeZX6PYFAy6b1eHvwWvbMhiVtbF1cjFySPnTpQTQ="
}
]
}
},
"username" : "bob",
"followings" : [
"5MJJPc78W3ipXpWzy"
]
}
Y码在这里:
库/路由器
FlowRouter.route('/users/:userid/followers', {
name: 'followers',
action(params) {
ReactLayout.render(MainLayout, {
content: <FollowersBox {...params}/>
});
}
});
server/publications
Meteor.publish('followers', (userId)=> {
check(userId, String);
Meteor.users.find({followings: userId});
});
clients/components/Profile/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>
)
}
});
发布于 2015-12-11 05:45:50
发布函数应该返回游标:
Meteor.publish('followers', (userId) => {
check(userId, String);
return Meteor.users.find({followings: userId});
});
https://stackoverflow.com/questions/34223287
复制