我目前正在尝试将特定文件夹中每个 JSON 文件的数据添加到字符串,然后将该字符串记录到控制台 - 但它不起作用。有没有人能够阐明我哪里出错了?
global.article = "";
for(i=0;i<posts.length;i++){
fs.readFile('posts/' + posts[i], 'utf8', function(err, json){
var post = JSON.parse(json);
article += "<article>";
article += "<blockquote>";
article += "<h3>" + post.title + "</h3>";
article += "<small>" + post.date + "</small>";
article += post.content;
article += "</blockquote>";
article += "</article>";
});
}
console.log(article);