【发布时间】:2018-08-02 10:59:16
【问题描述】:
我有这样的查询const result = await Form.findOne({ _id: req.params.id });
这是我的查询结果:
{ _id: 5a8ea110d7371b7e5040d5c9,
_user: 5a5c277f8d82ba3644b971c2,
formDate: 2018-02-22T10:53:04.579Z,
formElement:
{ formName: 'Vanilla Form',
pixel: '23423325',
fieldRows: [ [Object], [Object] ] },
formStyle:
{ globalColor: [ [Object], [Object], [Object] ],
elementSizing: 'medium',
elementStyle: 'radius',
fontFace: 'Open Sans',
fontSize: { label: '15', button: '15' } },
__v: 0,
status: true }
我正在尝试获得像这样的像素console.log(result.formElement.pixel)
但是,当我尝试获取像素值时,它返回 undefined。
怎么了?
更新
这是我的代码:
app.get("/view/:id", async (req, res) => {
const result = await Form.findOne({ _id: req.params.id });
console.log(result);
console.log(result.formDate); //return 2018-02-22T10:53:04.579Z,
console.log(result.formElement.pixel) //return undefined
// res.render("form", {
// result
// });
});
我尝试在不使用异步的情况下编辑我的代码,而不是使用 Promise,但它也返回 undefined
【问题讨论】:
-
调试 result.formElement.formName 并且没有异步等待。
-
返回
TypeError: Cannot read property 'formName' of undefined@StoychoTrenchev
标签: javascript express mongoose