我正在制作一个博客,使用
WordPress作为无头CMS
和
快速把手
查看。
在控制器中,我有:
var axios = require('axios');
exports.getHomepageData = async (req, res, next) => {
try {
let [postCaregoriesData, postData] = await Promise.all([
axios.get(`${base_url}/categories`),
axios.get(`${base_url}/posts?_embed`),
]);
const posts = postData.data;
const categories = postCaregoriesData.data;
posts.forEach(function(post){
console.log(post._embedded.author[0].name);
});
res.render('index',
{
layout: 'layout',
pageTitle: 'All posts',
categories: categories,
posts: posts,
});
} catch (error) {
res.status(500).json(error);
}
};
此行显示终端中的自动驾驶器名称:
posts.forEach(function(post){
console.log(post._embedded.author[0].name);
});
然而,在视图中,如果我成功地显示了文章标题,我会使用它来显示文章作者的姓名:
{{
{{this._embedded.author[0].name}}
{{/each}}
此操作失败,返回错误:
Expecting 'ID', got 'INVALID'
代码中缺少什么?