[英]Meteor Iron Router : Passing data between routes
How do I pass data between two different routes and templates? 如何在两个不同的路由和模板之间传递数据?
I have a javascript file on the front end (client folder) that simply calls Router.go() passing in the post ID as one of my parameters. 我在前端(客户端文件夹)上有一个javascript文件,它只调用Router.go()作为我的参数之一传入帖子ID。
Below are the three main culprits (I believe). 以下是三个主要罪魁祸首(我相信)。 I've removed most of the code to make it easier to read. 我删除了大部分代码,以便于阅读。 I can change to the PostDetail page with no problems. 我可以毫无问题地更改到PostDetail页面。 I can also retrieve the PostId on the PostDetail page from the Router. 我还可以检索从路由器PostDetail页面上的帖子ID。 My problem is, the database entry ( POLL ) that is retrieved does not get rendered on the template. 我的问题是,检索到的数据库条目( POLL )不会在模板上呈现。 Hence {{Question}} is always blank even though the database entry is being returned. 因此,即使返回数据库条目, {{Question}}也始终为空。
Let me know if I should post more information. 如果我发布更多信息,请告诉我。
FrontEnd.js FrontEnd.js
Template.PostTiles.events({
// When a choice is selected
'click .pin' : function(event, template) {
Router.go('Post', {_PostId: this.PostId});
}
});
post-detail.html 后detail.html
<template name="PostDetail">
<h3>{{Question}}</p>
</template>
Shared.js Shared.js
Router.map( function() {
this.route('Home', {
path: '/',
template: 'PostTiles',
data: {
// Here we can return DB data instead of attaching
// a helper method to the Template object
QuestionsList: function() {
return POLL.find().fetch();
}
}
});
this.route('Post', {
template: 'PostDetail',
path: '/Post/:_PostId',
data: function() {
return POLL.findOne(this.params._PostId);
},
renderTemplates: {
'disqus': {to: 'comments'}
}
});
});
----- Update ----- -----更新-----
I think I've narrowed down the issue to simply being able to render only one Database entry, instead of a list of them using the {{#each SomeList}} syntax. 我想我已经将问题缩小到只能呈现一个数据库条目,而不是使用{{#each SomeList}}语法来呈现它们的列表。
Looks like you found the answer / resolved this, but just in case, I think it's in your findOne
statement: 看起来你找到答案/解决了这个,但为了以防万一,我认为它在你的findOne
声明中:
data: function() {
return POLL.findOne(this.params._PostId);
},
should read: 应该读:
data: function() {
return POLL.findOne({_id:this.params._PostId});
},
(assuming that POLL has your posts listed by _id. (假设POLL的帖子由_id列出。
Hope that helps. 希望有所帮助。
Could you pass the info in the Session? 你能在会话中传递信息吗? the docs for that are here http://docs.meteor.com/#session . 这方面的文档在这里http://docs.meteor.com/#session 。 That's what I'm planning on doing. 这就是我打算做的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.