从Meteor中的JavaScript传递给模板的访问变量

时间:2015-07-18 15:59:34

标签: javascript meteor

我将变量传递给模板:

{{> myTemplate myVariable}}

在myTemplate中,我使用:

访问它
<template name="myTemplate">
  {{this}}
</template>

thismyVariable

如何从代码中访问myVariable - myTemplate的onCreated,onRendered,助手。

示例:

Template.myTemplate.onCreated(function(){
  // How access myVariable here?
});

Template.myTemplate.onRendered(function(){
  // How access myVariable here?
});

1 个答案:

答案 0 :(得分:1)

在onCreated和onRendered回调中,this.data指向传递的数据:

Template.myTemplate.onCreated(function(){
  console.log(this.data);
});

Template.myTemplate.onRendered(function(){
  console.log(this.data);
});