0

コメント(.../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}} は表示されません。また、{{#with post}} なしで {{> postItem}} のみをレンダリングしようとすると、html はレンダリングされますが、データはレンダリングされません。

コンソールに次のアラートが表示されます: パラメータが欠落している Route.prototype.resolve を呼び出しました。パラメータに「_id」が見つかりません

前もって感謝します!

4

2 に答える 2

1

テンプレートを小さなテンプレートに分割しようとするとどうなりますか? 私が間違っていなければ、同じ _Id を持たない限り、複数のデータ コンテキストを持つことはできないと思います。この場合、投稿とコメントの _Id は異なり、取得しているようなエラーがスローされます。次のようなことを試してください:

<template name="comment_reply">
    <div class="small-12 columns">
         {{# with post}}
              {{> postItem}}
         {{/with}}
    </div>
</template>

<template name="postItem">
    <div class="small-12 columns">
      {{#with comment}}
          {{> comment}}
      {{/with}}
     </div>
</template> 

<template name="comment">
     {{> commentReplySubmit}}   
</template> 

テンプレートの構文とルーティングをいじる必要があるでしょう。

お役に立てれば!

于 2013-12-28T19:34:54.277 に答える