我收到“无法读取未定义的属性‘重复’”错误,但在控制台记录时,似乎对象是/定义良好的,所以我不知道为什么代码会崩溃。这是doc对象的控制台日志:RESULT DOC: { _id: 5d9bc5c2bbb87318847cef91, authData: { dateEffective: { attr: [Object], value: [] }, username: { attr: [Object], value: [Array] }, password: { attr: [Object], value: [Array] }, mainEmail: { attr: [Object], value: [Array] }, _id: 5d9bc5c2bbb87318847cef86 }, nameData: { title: { attr: [Object], value: [Array], enum: [Array] }, firstName: { attr: [Object], value: [Array] }, middleName: { attr: [Object], value: [Array] }, familyName: { attr: [Object], value: [Array] }, suffix: { attr: [Object], value: [Array], enum: [Array] }, _id: 5d9bc5c2bbb87318847cef87 }. . .. . .这是控制台日志meta:META: { authData: { label: 'Authentication', depth: 4, hidden: false, repeats: false }, nameData: { label: 'Name', depth: 5, hidden: false, repeats: false },. . . . . . }users_controller.js- 有问题的路线。. . exports.user_details_post = [(req, res, next)=> { //LOG console.log(`Request: ${util.inspect(req.body)}`); // <-- ALL GOOD HERE next(); }, //VALIDATE body('email', 'Must be valid email.').isLength({min: 5}).trim(), //SANITIZE sanitizeBody('*').escape(), //SAVE (req,res, next) =>{ let user = UserObj.findById(req.params.id, function(err,doc){ const errors = validationResult(req); let activeArr = []; let maxActive = 0; } }) }];显然,Object.keys(doc).forEach(sec=> . . . )结构似乎有问题,因为sec是走出来的$___,而不是authData,nameData等我可以将迭代通过Object.keys(doc),如果是我在做什么错?
1 回答
拉莫斯之舞
TA贡献1820条经验 获得超10个赞
与其过滤特定的键,不如先检查该键是否存在meta。
Object.keys(doc).forEach(sec => {
if (meta.hasOwnProperty(sec) && meta[sec].repeats) {
...
}
});
添加回答
举报
0/150
提交
取消