【发布时间】:2019-03-28 06:24:52
【问题描述】:
我使用 Handlebars 作为我的模板引擎,并且是 Handlebars 的新手。我从 API(edamam recipe search api)传递了数据。当尝试使用表单中的隐藏值发回附加到每个食谱卡的成分数组时,我在服务器端收到错误消息。控制台显示
[对象对象],[对象对象],[对象对象],[对象 对象],[对象对象],[对象对象] [对象对象],[对象 对象],[对象对象],[对象对象],[对象对象],[对象 对象]
尝试在服务器端注销时。不知道发生了什么。代码如下:
<div class="container">
<header class="jumbotron">
<div class=container></div>
<h1>{{currentUser.username}}</h1>
<h1>Press save to add the recipes to your dashboard</h1>
<p>
<a class="btn btn-primary btn-large" href="/{{currentUser.username}}/recipes/dashboard">Go To Your Dashboard</a>
</p>
</header>
<div class="row text-center" style="display:flex; flex-wrap:wrap">
{{#each data}}
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<img src="{{recipe.image}}" alt="Recipe Pic">
<div class="caption">
<h4>
{{recipe.label}}
</h4>
<h5>
Ingredients
</h5>
{{!-- recipe.ingredients is an array of ingredient objects with text as a key --}}
{{#each recipe.ingredients}}
<p>{{text}}</p>
{{/each}}
</div>
<p>
<form id="buttonDesign" action="/recipes/dashboard" method="POST">
<input type="hidden" name="recName" value="{{this.recipe.label}}"/>
<input type="hidden" name="recImage" value="{{this.recipe.image}}"/>
<input type="hidden" name="recUrl" value="{{this.recipe.url}}"/>
<input type="hidden" name="recIngredients" value "{{this.recipe.ingredients}}"/>
<button class="btn btn-primary">Save</button>
</form>
</p>
</div>
</div>
{{/each}}
</div>
</div>
</div>
如上所述,当我在服务器端注销 req.body.recIngredients 时,我收到 [object, Object] 错误。
【问题讨论】:
-
在最后一个隐藏字段中缺少
=吗? -
missing = on recIngredients 字段 -->AND--> 表单提交需要按钮类型 --->
标签: javascript express handlebars.js