虽然在节点js中更新记录,但我能够为文本输入字段呈现值,但是在更新形式中,单选按钮和textarea的值不会出现。谁能让我知道如何实现它。我正在使用hbs模板。
<div class="form-group row">
<label for="inputPassword3" class="col-sm-5 col-form-label" style="color: #2874a6 ;">Owner Name</label>
<div class="col-sm-6">
<input type="email" class="form-control" name="owner" value={{product.owner}}>
</div>
</div>
<div class="form-group row">
<label for="inputPassword3" class="col-sm-5 col-form-label" style="color: #2874a6 ;">Description</label>
<div class="col-sm-6">
<textarea class="form-control" name="description" rows="2" value={{product.description}}></textarea>
</div>
</div>
<div class="form-group row">
<label for="inputPassword3" class="col-sm-5 col-form-label" style="color: #2874a6 ;">Summary column format</label>
<div class="col-sm-6">
<div class="radio-inline">
<input class="form-check-input" type="radio" name="taskDone" value="Yes" onClick="changeresult();">if({{product.team}}=="Yes"){ %> checked
<%} %>> Yes </input>
</div>
<div class="radio-inline">
<input class="form-check-input" type="radio" name="taskDone" value="No" onClick="changeresult();">if({{product.taskDone}}=="Yes"){ %> checked
<%} %>> Yes </input>
</div>
</div>
</div>
textarea字段和单选按钮的值不出现。谢谢您的帮助
我不定期与handlebars
合作,因此您可能需要进行其他研究。
似乎[{{if}}
doesn't support comparisons, only existence and booleans。因此,根据一些研究,您可以选择几种方法:
选项1:布尔值您可以将值作为布尔值提供给模板。因此,让中间件(甚至更好地更新数据库架构并进行相应存储)不是“是”,“否”,而是将它们提供为true
,false
。然后您可以使用:
{{#if product.team}} checked {{/if}}
选项2:注册一个助手
在您的JavaScript代码中注册帮助器:
Handlebars.registerHelper('ifEquals', function(arg1, arg2, options) {
return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
});
在模板中使用:
{{#ifEquals product.team "Yes"}} checked {{/ifEquals}}