我想创建一个可以回复评论的路线(.../comments/:_id/reply),但在发布与评论相关的帖子时遇到问题。
这是代码:
出版物
Meteor.publish('commentUser', function(commentId) {
var comment = Comments.findOne(commentId);
return Meteor.users.find({_id: comment && comment.userId});
});
Meteor.publish('commentPost', function(commentId) {
var comment = Comments.findOne(commentId);
return Posts.find({_id: comment && comment.postId});
});
Meteor.publish('singleComment', function(commentId) {
return Comments.find(commentId);
});
路线
this.route('comment_reply', {
path: '/comments/:_id/reply',
waitOn: function() {
return [
Meteor.subscribe('singleComment', this.params._id),
Meteor.subscribe('commentUser', this.params._id),
Meteor.subscribe('commentPost', this.params._id)
]
},
data: function() {
return {
comment: Comments.findOne(this.params._id)
}
}
});
评论回复模板
<template name="comment_reply">
<div class="small-12 columns">
{{# with post}}
{{> postItem}}
{{/with}}
</div>
<div class="small-12 columns">
{{#with comment}}
{{> comment}}
{{/with}}
</div>
{{> commentReplySubmit}}
</template>
评论回复助手
Template.comment_reply.helpers({
postItem: function() {
return Posts.findOne(this.comment.postId);
}
});
当我访问该路线时,{{#with comment}} 会正确呈现,但 {{#with post}} 不会出现。如果我尝试只渲染 {{> postItem}} 而没有 {{#with post}} 它会渲染 html,但没有数据。
控制台打印此警报:您调用 Route.prototype.resolve 时缺少参数。在参数中找不到“_id”
提前致谢!