在我post_item.html我得到這一行:如何通過一個會話befor路由與鐵:流星路由器?
<a href="{{pathFor 'postPage' _id=this._id}}" class="discuss btn">Discuss</a>
在我router.js:
Router.map(function() {
this.route('postPage',{path:'/posts/:_id',
beforeRoutingTo: function(id) {
console.log("hello!");
Session.set('currentPostId', id);
}
});
});
在我post_page.js
Template.postPage.helpers({
currentPost: function() {
return Posts.findOne(Session.get('currentPostId'));
}
});
在我post_page.html
<template name="postPage">
{{#with currentPost}}
{{> postItem}}
{{/with}}
</template>
我做錯了什麼? 如何將ID傳遞到新的「頁面」並顯示結果?
WOW!那真的有用!我嘗試了很長一段時間很多不同的類型... 我想這樣做更多,但它不工作: 'Router.route('/ post /:_ id',{ name:'postPage' , 數據:功能(){ 返回 Posts.findOne(this.params._id);} });' 在post_item.html: ''Discuss 而在post_page.html '<模板名稱=「postPage」>
只是在這種情況下,我想顯示更多的只是項目,我需要post_pa ge.html用於向該單擊的項目添加更多詳細信息。 我只有老書「發現流星」 - 我看到了這本書的版本(用德語) - http://de.discovermeteor.com/chapters/routing/ – Suisse
OK thx!我測試了一下你的代碼並將其改爲: route.js: 'this.route('/ post /:_ id',function(){ var item = Posts.findOne({_ id:this.params ._id}); this.render( 'postPage',{數據:項});} , { 名: 'postPage' });' 在post_item。HTML的討論鏈接: ''Discuss在 我post_page.html可以添加更多的詳細信息: '<模板名稱= 「postPage」>