在我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”>