【发布时间】:2014-06-13 18:52:42
【问题描述】:
我有一个参与者正在这个模板中呈现:
<template name="participant">
<div class="animated fadeIn">
<a href="{{pathFor 'participants'}}">← Back</a>
{{#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 name="email" value=email}}
<p> </p>
<h5><a href="#" class="delete">Delete</a></h5>
</div>
{{/with}}
</div>
</template>
Quickfield 模板在哪里:
<template name="quickfield">
<input id="{{name}}" value="{{value}}" class="bound">
</template>
我想跳过模板调用中称为“值”的第二个参数,因为它与名称参数相同。我们应该可以只用一个参数来构建模板。
理想情况下,我应该有这个:
{{>quickfield name="email"}}
<template name="quickfield">
<input id="{{name}}" value="{{eval('this.' + name)}}" class="bound">
</template>
但这不起作用。我该怎么办?
谢谢!
【问题讨论】:
-
我不太明白这个问题。为什么不能只使用
id="{{name}}" value="{{name}}"? -
因为name是字符串“email”,value应该是参与者的email“info@foo.com”。
-
现在知道了。是的,空格键的理解非常有限,但值得庆幸的是,你几乎可以用合适的助手制作任何东西。请参阅下面的答案。
标签: meteor handlebars.js