【发布时间】:2015-10-11 17:20:55
【问题描述】:
已经两周了,我仍然无法让 cmets 出现在他们写的帖子中。每个评论都会出现在每个帖子中。在尝试了很多不同的教程、信息或视频(基本上是谷歌和流星文档给我的所有内容)后,我几乎精神崩溃了,但我一直失败得很惨......
服务器:
Meteor.publish("posts", function () {
return Posts.find();
});
Meteor.publish("comments", function() {
return Comments.find();
});
Single-post.js
Template.singlePost.helpers({
comments: function () {
return Comments.find({},{sort: {createdAt: -1}});
}
});
Template.singlePost.events({
"submit .new-comment": function (event) {
var text = event.target.text.value;
Meteor.call("addComment", text);
event.target.text.value = "";
return false;
}
});
Meteor.methods 内部:
addComment: function (text) {
if (! Meteor.userId()) {
throw new Meteor.Error("not-authorized");
}
Comments.insert({
text: text,
createdAt: new Date(),
owner: Meteor.userId(),
username: Meteor.user().username
});
},
最后是路由器:
Router.map(function(){
this.route('top', {path:'/top'});
this.route('trending', {path:'/trending'});
this.route('new', {path:'/new'});
this.route('singlePost', {path:'/post/:_id',
data:function(){
return Posts.findOne({_id:this.params._id})
}
});
})
我知道我没有在路由器中包含评论或缺少有关 cmets 的其他一些内容,因为我尝试了无数不同的事情但都失败了,所以我想为我未来的助手保持干净......
提前致谢!
【问题讨论】:
标签: meteor