在我的流星应用程序中,我有一个数据收集表单模板,如下所示:
<template name="IntroductionWizard_Step_1">
{{#with contributor}}
<div class="container">
<div class="hero-unit">
<h3 class="panel-title">Introduction Wizard Step 1: </h3>
<form class="form-vertical" role="form">
<label for="name" class="control-label"><h5 class="text-muted">Name</h5></label>
<input type="text" id="name" name="name" class="form-control-element" value="{{contributorName}}" placeholder="Name">
<label for="email" class="control-label">Email</label>
<input type="text" id="email" name="email" class="form-control-element" value="{{contributorEmail}}" placeholder="Email">
<label for="phone" class="control-label">Phone</label>
<input type="text" id="phone" name="phone" class="form-control-element" value="{{contributorPhone}}" placeholder="phone #">
<label for="orgRole" class="control-label">Org Role</label>
<input type="text" id="orgRole" name="orgRole" class="form-control-element" value="{{contributorOrgRole}}" placeholder="Org Role">
</form>
</div>
</div>
{{/with}}
</template>
这个模板的助手如下所示:
Template["IntroductionWizard_Step_1"].helpers({
contributor: function(n) {
return ContributorCollection.findOne({contributorName: "Jim Szczygiel"});
}
});
此助手可以返回数据(如果找到),也可以不返回数据。当前,当返回数据时,它以这种形式显示,但是,当没有数据返回时,该页面显示为空-根本没有显示表单模板。即使没有返回数据,我该怎么办仍显示一个空的模板表单?
with
就像if
加一个名称空间一样,所以您所看到的很有意义-整个表格将有条件地删除。可能的工作是删除with
,而对每个值使用全名。例如:
value="{{contributor.contributorName}}"
我只是做了一点测试,发现即使contributor
没有定义,它似乎也没有失败。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句