我正在Nodejs中进行评论和回复评论功能 我的数据库表包含为image 这是我的代码,显示所有评论及其回复
module.exports.viewCommentOfProduct = (req, res, next)=>{
Comments.findAll({
where: {
productsid: req.params.id
}
})
.then(comments=>{
res.json({
comments: comments
})
})
.catch(err=>{
res.json('Err: '+ err);
})
}
但是,这不是我所需要的。 我想以树状视图的形式响应JSON
comment: [
{
id: 1
usersid:
productsid:
title:
content:
reply: [
{id:1, usersid:, title: , content:},
{id:2, usersid:, title: , content:}
.... and so on
]
}
]
我想在显示所有评论时推送所有评论。 您能为我推荐如何解决这个问题吗?