Node.js 如何在获取数据后阻止页面继续加载
我有一篇博客文章,随时都可以根据我保存的博客id获取评论 基于id的注释,它将工作,但我的页面将继续加载,我将看到无法读取属性 控制台上的''u id'为null,而我已获得所需的数据。 在获取数据之后,我如何阻止页面继续加载,以及为什么在控制台上看到“无法读取null的属性”\u id 这是密码Node.js 如何在获取数据后阻止页面继续加载,node.js,express,ejs,Node.js,Express,Ejs,我有一篇博客文章,随时都可以根据我保存的博客id获取评论 基于id的注释,它将工作,但我的页面将继续加载,我将看到无法读取属性 控制台上的''u id'为null,而我已获得所需的数据。 在获取数据之后,我如何阻止页面继续加载,以及为什么在控制台上看到“无法读取null的属性”\u id 这是密码 router.get('/articles/:slug', async (req, res) => { try { const singleBlog = await blog
router.get('/articles/:slug', async (req, res) => {
try {
const singleBlog = await blogModel.findOne({ slug: req.params.slug }).populate('creator')
//Fetch comments based on singleBlog Post
const blogComments = await commentModel.find({ post: singleBlog._id })
const category = await catModel.find()
const catCount = []
for(let i = 0; i < category.length; i++) {
const countIt = await blogModel.countDocuments({category: category[i].catname});
catCount.push({name:category[i].catname, count:countIt});
}
return res.render('front/blog_details', {
singleBlog,
blogComments,
catCount, category
})
} catch (err) {
console.error(err.message)
}
})
router.get('/articles/:slug',异步(req,res)=>{
试一试{
const singleBlog=await blogModel.findOne({slug:req.params.slug}).populate('creator'))
//基于singleBlog帖子获取评论
const blogcoments=await commentModel.find({post:singleBlog.\u id})
const category=wait catModel.find()
常数catCount=[]
for(设i=0;i
在发送响应之前,是否可以检查for循环是否已完成。当我注释掉for循环时,它仍然具有相同的内容