nodejs建站-回复评论

评论回调方法提取用户名

exports.detail=function(req,res){
	var id=req.params.id
	Movie.findById(id,function(err,movie){
	 	Comment.find({movie: id},function(err,comments){
	 		console.log(comments)
	 		res.render('detail',{
			title:movie.title,
			movie:movie,
			comments:comments
			// {title:'momo',
			// country:'USA',
			// year:'2014',
			// flash:'http://www.imooc.com/video/1226/0',
			// summary:'你好试试'}
		})
	 	})
	})
}

使用populate获取用户名

exports.detail=function(req,res){
	var id=req.params.id
	Movie.findById(id,function(err,movie){
	 	Comment.find({movie: id})
	 		.populate('from','name')
	 		.exec(function(err,comments){
	 		console.log(comments)
	 		res.render('detail',{
			title:movie.title,
			movie:movie,
			comments:comments
			// {title:'momo',
			// country:'USA',
			// year:'2014',
			// flash:'http://www.imooc.com/video/1226/0',
			// summary:'你好试试'}
		})
	 	})
	})
}

与其有关联的对象设置为replay

comment中初始化: movie,from.,replay,mata,content,to
修改to为
	replay:{
		from:{type:ObjectId,ref:'User'},
		to:{type:ObjectId,ref:'User'},
		content:String 
		},	
在jade文件中对用户图片添加锚点#comments

将所有的回复加到主评论的回复中,实现对子回复的回复

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值