将参数从 Router 传递到 Meteor 上的模板助手
Pass parameters from Router to Template's helper on Meteor
我有一个路由器定义如下
Router.route('/profile/:input',function(){
this.render('profile');
});
所以我可以调用 this.params.input
得到 input
的值。我想在 MongoDB 上查询此值并传递给模板配置文件。但是我怎样才能将这些信息从 Router 交换到 helper?
if (Meteor.isClient) {
Template.profile.helpers({
data: function(){
//what to do?!
}
});
}
在您的 Template.foo.helpers 内部,您可以通过以下方式获取路由器参数:
Router.current().params.input
我有一个路由器定义如下
Router.route('/profile/:input',function(){
this.render('profile');
});
所以我可以调用 this.params.input
得到 input
的值。我想在 MongoDB 上查询此值并传递给模板配置文件。但是我怎样才能将这些信息从 Router 交换到 helper?
if (Meteor.isClient) {
Template.profile.helpers({
data: function(){
//what to do?!
}
});
}
在您的 Template.foo.helpers 内部,您可以通过以下方式获取路由器参数:
Router.current().params.input