[英]Meteor getting data from router
I'm having trouble getting data from iron:router. 我无法从iron:router获取数据。 Im trying to get the data by param._id and then pass it to my template.created to set a session variable for editing purposes. 我试图通过param._id获取数据,然后将其传递给我的template.created以设置会话变量以进行编辑。
Here is my code in the router: 这是我在路由器中的代码:
Router.route('/edit/:_id', function(){
this.render('edit', {
data: function(){
return Collection.findOne({_id: this.params._id})
}
})
})
And then I want to access that data here: 然后我想在这里访问该数据:
Template.edit.created = function(){
data = ???
Session.set('edit', data)
$(input).val(data.post)
}
If i do console.log( this )
I get Blaze.TemplateInstance
. 如果我做console.log( this )
我得到Blaze.TemplateInstance
。
But when I console.log(this)
in Template.edit.events I get the document I want from the iron:router. 但是当我在Template.edit.events中的console.log(this)
,我从iron:router获得了我想要的文档。
I've used Template.currentData();
我用过Template.currentData();
and managed to access the data in template.created but can someone explain why "this" in template.created and template.events refers to 2 different things? 并设法访问template.created中的数据,但是有人可以解释为什么template.created和template.events中的“ this”引用2种不同的东西吗?
对于template.created和template.rendered,可以使用this.data
访问数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.