express框架populate方法渲染模版出问题

我用这种方法查询时

let articles = await Article.find()

res.send(articles)会得到

[

{"cover": "\\uploads\\upload_a3770506ec4a3f5708ded093cc3f9c73.PNG",

"_id": "60b71a37ccf6920aec6992ad",

"title": "测试文章","

author": "60b22f16cc21cb31fc8f88a6",

"publishDate": "2021-06-04T00:00:00.000Z",

"content": "<p>大风歌</p>","__v": 0}

]

然后注释掉res.send 换成:

res.render('admin/article.art' ,{articles:articles});

把数据{{$value.author}}渲染到模板中

 {{each articles}}

                    <tr>

                        <td>{{@$value._id}}</td>

                        <td>{{$value.title}}</td>

                        <td>{{$value.publishDate}}</td>

                        <td>{{$value.author}}</td>

{{/each articles}}

能正常渲染.

当换成这种关联查询时

 let articles = await Article.find().populate('author');

res.send(articles)会得到

[

{"cover": "\\uploads\\upload_a3770506ec4a3f5708ded093cc3f9c73.PNG",

"_id": "60b71a37ccf6920aec6992ad","title": "测试文章",

"author": {"state": 0,"_id": "60b22f16cc21cb31fc8f88a6","username": "lituiping","email": "2869161658@qq.com","password": "$2b$10$y8oCNXQeekb3taymn7/5deS0IuTpU9RXNl/l553dbyp89820qKJt.","role": "admin","__v": 0},

"publishDate": "2021-06-04T00:00:00.000Z",

"content": "<p>大风歌</p>","__v": 0}

]

然后注释掉res.send 换成:

res.render('admin/article.art' ,{articles:articles});

把数据{{$value.author.username}}渲染到模板中

 {{each articles}}

                    <tr>

                        <td>{{@$value._id}}</td>

                        <td>{{$value.title}}</td>

                        <td>{{$value.publishDate}}</td>

                        <td>{{$value.author.username}}</td>

{{/each articles}}

就会报错不知道什么原因

报错:SyntaxError: Unexpected token R in JSON at position 0

你好,我是有问必答小助手。为了技术专家团更好地为您解答问题,烦请您补充下(1)问题背景详情,(2)您想解决的具体问题,(3)问题相关代码图片或者报错信息。便于技术专家团更好地理解问题,并给出解决方案。

您可以点击问题下方的【编辑】,进行补充修改问题。