首先感谢您帮我看这个问题,非常感谢
描述问题
整体采用Node.js的Express框架
我在数据库(MongoDB)中读取一个回答的评论对象(
answerComment
)出来,然后根据评论作者的ID读取了这个评论的作者信息(也是一个对象author
)通过
answerComment.author = author;
,进行赋值,然后通过console.log(answerComment.author);
显示了author这个对象的值;但是通过
res.status(200).json({comment: answerComment});
这句话向前端传递数据的时候,在前端通过var response = JSON.parse(request.responseText);
获得response之后,使用console.log(response.answerComment.author)
却是undefined
,输出console.log(response.answerComment)
的数据是有数据的,形式如下:
{
"__v":0,
"content":"de",
"author_id":"56e5944be3f709ad4c0395db",
"_id":"56efb9e40e28dd4427fd23a9",
"comment_count":0,
"deleted":false,
"dislikes":[],
"likes":[],
"update_at":"2016-03-21T09:07:48.105Z",
"create_at":"2016-03-21T09:07:48.105Z"
}
response.anserComment
这个对象不是没有author
吗? 只有author_id
~~