【发布时间】:2021-12-18 10:10:04
【问题描述】:
快递/打字稿:
export const updateSettings = catchErrors(async (req, res) => {
console.log("updateSettings req.body: ", req.body)
const { organizationId, formdata, updatedItems, updateQuota } = req.body;
console.log("organizationId: ", organizationId);
console.log("formdata: ", formdata);
console.log("updatedItems: ", updatedItems);
console.log("updateQuota: ", updateQuota);
console.log("req.body.updateQuota: ", req.body.updateQuota);
res.respond({'message': 'Settings updated successfully!' })
});
req.body 的控制台日志如下:
updateSettings req.body: {
username: 'staff_a',
organizationId: '2',
formData: '{"offDays":[0,6,1],"officeHourStart":"1899-12-31T09:00:00.000+09:00","officeHourEnd":"1899-12-31T18:00:00.000+09:00","displayLanguage":"cn","timezone":"beijing","doctorQuotas":{"5":5,"6":10}}',
updatedItems: [ 'displayLanguage', 'timezone', 'billingClosingDay', 'offDays' ],
updatedQuota: [ 6, 5 ]
}
如您所见,有updatedQuota 和updatedItems 字段。一个是字符串数组,另一个是数字数组;
但是,在析构行const { organizationId, formdata, updatedItems, updateQuota } = req.body; 之后,有些字段没问题,但有些字段变得未定义:
organizationId: 2
formdata: undefined
updatedItems: [ 'displayLanguage', 'timezone', 'billingClosingDay', 'offDays' ]
updateQuota: undefined
如果我通过打印 console.log("req.body.updateQuota: ", req.body.updateQuota);单独访问req.body.updateQuota,它也是空的:
req.body.updateQuota: undefined
为什么req.body中明明有东西,却无法访问或提取?
【问题讨论】:
-
错字:
updateQuotaupdatedQuota,formDataformdata
标签: javascript node.js typescript express