0
我正在使用流星来构建类似于reddit的网站。我用account-ui
包用户帐户,但我无法获得用户价值。我能够创建一个帐户和登录,但是当我发表评论时,它显示我是匿名用户。下面的代码 -流星 - 注册帮助器,无法访问用户值
Template.registerHelper('getUser', function(user_id) {
var user = Meteor.users.findOne({_id: user_id});
if (user) {
return user.username;
}
else {
return "anon";
}
});
后评论 -
Template.comment_form.events({
"submit .js-save-comment-form":function(event){
if (Meteor.user()) {
// here is an example of how to get the comment out of the form:
var comment = event.target.comment.value;
console.log("The comment is: "+comment);
Comments.insert({
website: Router.current().params._id,
comment: comment,
createdOn: new Date(),
user: Meteor.user()._id
});
event.target.comment.value = "";
}
else {
alert('You need to be logged in to submit comments!');
}
return false; // stop the form submit from reloading the page
}
});
我登录的用户测试,但是当我发布的评论,这表明它的发表不久,这意味着服务器没” T回流用户价值
您是否发布和订阅? – Areca
您确定发布了“用户名”字段和相关的用户详细信息吗?请分享相关模板和帮助代码,并确保输入的内容符合您的期望。 – MasterAM