「postlist」テンプレートに名前のリストがあります。これらは、投稿を作成した人の「ユーザー名」です。ユーザーが名前をクリックすると、新しいテンプレート「viewpost」にルーティング/誘導され、投稿ドキュメント全体を表示できるように、href リンクを作成しました。
しかし、代わりに「postlist」テンプレート内に {{> yield}} を配置した場所に「viewpost」テンプレートをレンダリングしたいと思います。アプリの別の部分で機能するlayourTemplateが既にあるため、layourTemplateを構成するにはどうすればよいですか。
もちろん、この投稿ドキュメントは、ユーザーがクリックした名前に応じて変更する必要があります。
Meteor todos の例を考えてみてください。「参加」または「サインイン」のどちらをクリックするかに応じて、関連するテンプレートがレンダリングされます。
だから私がこれまでに持っているものは次のとおりです。
postlist.html (投稿ドキュメントの「フルネーム」フィールドのリストを表示)。
<template name="postlist">
<div class="container">
<div class="col-sm-3">
{{#each post}}
<li><a href="{{pathFor 'viewpost'}}" >{{fullname}}</a></li>
{{/each}}
</div>
</div>
{{> yield}}
</template>
router.js
Router.map(function(){
this.route('postlist',{
path: '/postlist',
template: 'postlist',
waitOn: function(){
return Meteor.subscribe('posts');
},
data: function(){
return {post: Posts.find({})};
}
});
this.route('viewpost',{
path: '/viewpost/:_id',
template: 'viewpost',
waitOn: function(){
return Meteor.subscribe('posts');
},
data: function() { return Posts.findOne(this.params._id); }
});
});