将参数添加到子模板时,Meteor会丢失数据上下文

时间:2014-06-14 12:48:15

标签: meteor handlebars.js

我有这个页面:

<template name="participant">
      {{#with participant}}
        <div class="participant">
          <h3>{{fullname}}</h3>
            <dl>
                <dt>E-mail</dt>
                <dd>{{email}}</dd>
                <dt>Phone</dt>
                <dd>{{tel}}</dd>
                <dt>City</dt>
                <dd>{{zip}} {{city}}</dd>
                <dt>Creation time</dt>
                <dd>added {{created_on}}</dd>
            </dl>
            {{>quickfield}}
        </div>
      {{/with}}
</template>

<template name="quickfield">
    <input id="{{email}}" value="{{email}}" class="bound">
</template>

它工作正常。

现在,如果我想在我的quickfield子模板中添加一个参数并执行此操作:

{{>quickfield name="foo"}}
<template name="quickfield">
    <input id="{{name}}" value="{{email}}" class="bound">
</template>

数据上下文丢失(之前,此=参与者,之后,此=窗口)。 {{email}}不再呈现。

为什么这样,解决方法是什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

也许您可以访问父上下文:

<template name="quickfield">
  <input id="{{name}}" value="{{../email}}" class="bound">
</template>