从bodyParser身份不明

问题描述 投票:0回答:1

我刚刚开始学习nodejs + express + handlebars,而我在发布时遇到了困难。这是我正在接收的请求正文,我似乎无法使用req.body.province和req.body.municipality获得“省和自治市”数据,但是只要有条件,我就可以。

{
'province ': 'ALBAY',
  'municipality ': 'BACACAY',
  bearing: '>=1 and <=20'
}

这是我从市和省表格中获取数据的方式。

<div class="form-group">
<label for='municipality'>Municipality</label> <select type= "text" name="municipality " class="form-control"> {{#each municipality}}
 <option>{{municipality}}</option> 
{{/each}} </select>

这是为了轴承。

<div class="form-group">
<label for="bearing">Bearing Trees</label> <select type="text" name="bearing" class="form-control">
 <option>>=1 and <=20</option>
<option>>=21 and <=50</option>
<option>>=51 and <=100</option> <option>>100</option> </select> </div>

我有点卡住了,我需要你们的帮助。谢谢

html node.js express handlebars.js body-parser
1个回答
0
投票

据我所见,与市和省对应的键的末尾有一个空格。

在一个对象内,所有键都是字符串类型,这意味着除非您使用符号,否则将包括空格。

对于您的问题,这是最重要的错字。

您想要的对象应该看起来像这样:

{
    province: 'ALBAY',
    municipality: 'BACACAY',
    bearing: '>=1 and <=20'
}
© www.soinside.com 2019 - 2024. All rights reserved.