在更新节点js中的记录时,我能够呈现文本输入字段的值,但在更新表单中,单选按钮和文本区域的值不会出现。我正在使用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>文本区域字段和单选按钮的值不存在。提前感谢您的帮助
发布于 2020-04-24 21:24:17
我不经常和handlebars一起工作,所以你可能需要做额外的研究。
看起来可能是{{if}} doesn't support comparisons, only existence and booleans。因此,根据一些研究,您有几个选择:
选项1:布尔值
您可以将值作为布尔值提供给模板。因此,与其说“是”或“否”,不如让中间件(或者更好地更新您的数据库模式并相应地存储它们)以true、false的形式提供它们。然后你可以使用:
{{#if product.team}} checked {{/if}}
选项2:注册帮助器
在javascript代码中注册helper:
Handlebars.registerHelper('ifEquals', function(arg1, arg2, options) {
return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
});在模板中使用:
{{#ifEquals product.team "Yes"}} checked {{/ifEquals}}https://stackoverflow.com/questions/61392324
复制相似问题