javascript - req.body 无法解析来自名称属性数组的输入
问题描述
我有一个带有一些名称属性数组的表单。目前,我有两个问题。
(1) 提交表单后,我无法解析 itemName[]、itemValue[]、itemQuantity[] 中的数组值。
(2) 我不明白为什么 itemName[], itemValue[], itemQuantity[] 是对象中的字符串。
谁能告诉我我做错了什么?
{ sessionUser: '5ae767331e2086537a6026be',
senderName: 'Mr. Camden Denesik',
senderPhone: '411-431-6729 x28435',
senderEmail: 'Pink.Boyer5@yahoo.com',
senderAddress: '3324 Marvin Hollow',
senderCity: 'South Ariannaland',
senderProvince: 'Iowa',
senderPostalCode: '61394-2622',
senderCountry: 'Libyan Arab Jamahiriya',
recipientName: 'Mac Keeling',
recipientIdNumber: '17462',
recipientPhone: '009-180-3472',
recipientEmail: 'Lucas_Schultz67@gmail.com',
recipientAddress: '91928 Bobbie Port',
recipientCity: 'Catharineside',
recipientProvince: 'Iowa',
recipientPostalCode: '80415',
recipientCountry: 'Montserrat',
'itemName[]': [ 'microchip', 'Kaka' ],
'itemValue[]': [ '135.00', '100' ],
'itemQuantity[]': [ '95065', '20' ],
itemTotalValue: '4.00',
insurance: 'on',
cargoInsurance: '893.00' }
解决方案
(2) This is how javascript handle attributes with special characters, try accessing the variables like a dictionary array obj['itemName[]']
. The best way to avoid this is to remove the []
from the attribute names.
As for (1) I don't fully understand your problem but I guess it has something to do with the inability to access the variables.
推荐阅读
- html - 只需将 HTML 代码传输到其他 HTML 文件中
- java - 在 IntelliJ IDEA 中调试时,如何防止线程挂起时变量受到影响?
- java - 为什么 Java 在主源文件夹中找不到文件?
- java - Kotlin / Java - 接口实现 + 继承
- dialogflow-es - 从 Dialogflow CX 中删除项目
- javascript - setState 中的直接参数和回调有什么区别?
- mongodb - Ansible 事实是条件中未定义的错误
- html - 如何在 html 中以小边距向标题添加背景
- python - 同时访问列表中所有元素的属性
- javascript - 如何让图像在 HTML 中显示一定次数的 Val