1
請參閱下面的代碼,請:訪問鐵路由器數據
Router.route('/posts/:_id', function() {
this.render('Post', {
to: 'content',
data: function() {
return Posts.findOne({id: this.params._id});
}
});
});
如果Post
對象有title
和body
的Fileds在MongoDB中,我可以從Post.html
模板訪問他們喜歡
<h4>Post title: {{title}}</h4>
<h3>Post body: {{body}}</h4>
我想在模板幫助函數中訪問Post
對象Post.js
。可能嗎?
更新: 根據這個問題:Meteor data-context with iron-router,我可以訪問data
變量是這樣的:
Template.Post.rendered = function() {
console.log(this.data)
}
有沒有辦法做到這裏面Template.Post.events
?