在Meteor中使用来自铁路由器的模板助手上的参数

时间:2015-11-13 20:27:48

标签: javascript meteor

我正在使用具有此特定路线的路由器:

Router.route('/organizations/:id', function () {
  this.render('organizationDetail', {id: this.params.id});
});

这使得' organizationDetail'模板。

我有这个模板的帮助者:

if (Meteor.isClient) {
  Template.organizationDetail.helpers({
    organization: function() {
        this.params.id????
        return FindById(id);
    }
  });
}

如何访问id变量以询问正确的对象?

1 个答案:

答案 0 :(得分:1)

您需要将该参数放入数据上下文中:

Router.route('/organizations/:id', function () {
  this.render('organizationDetail', {
      data: function() {
         return {id: this.params.id};
      }
  });
});

然后您可以直接从this对象中使用它,该对象将数据上下文保存在帮助程序中:

if (Meteor.isClient) {
  Template.organizationDetail.helpers({
    organization: function() {
        return FindById(this.id);
    }
  });
}
相关问题