nodejs 盖楼评论
评论
mongodb增删改查
短信验证
socket.io聊天
sh /root/
robomongo
ajax异步调用
短信验证
在线聊天
javascript序列化对象serialize
session req.session
商品首页、详情页、列表页用mongodb交互实现
express
-
准备测试的Json数据:
var a = [
{
"id": "1",
"Name": "caoyuan",
"Time": "201608230720",
"Content": "今天天气好"
},
{
"id": "2",
"Name": "cao",
"Time": "201608230722",
"Content": "这是1楼"
},
{
"id": "3",
"Name": "yuan",
"Time": "201608230723",
"Content": "这是2楼"
},
{
"id": "4",
"Name": "caoxuan",
"Time": "201608230724",
"Content": "这是3楼"
}
];
-
样式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<style>
.commentbox{
border:1px solid #ccc;
padding: 10px;
margin: 2px;
}
</style>
<div class="commentbox" id="pl">
我还没吃饭,你们吃了么
<div class="commentbox" id="pl">
爽爽的贵 阳欢迎你
<div class="commentbox" id="pl">我在贵阳等你</div>
</div>
</div>
</body>
</html> -
拼接
<script type="text/javascript">
var a = [
{
"id": "1",
"Name": "caoyuan",
"Time": "201608230720",
"Content": "今天天气好"
},
{
"id": "2",
"Name": "cao",
"Time": "201608230722",
"Content": "这是1楼"
},
{
"id": "3",
"Name": "yuan",
"Time": "201608230723",
"Content": "这是2楼"
},
{
"id": "4",
"Name": "caoxuan",
"Time": "201608230724",
"Content": "这是3楼"
}
];
var result = "";
result += "<div id='aqplgl' style='text-indent:1em;background-color: #eeeeee;border: 1px solid #000000;margin-left: 3px;margin-right: 3px;margin-top: 3px;margin-bottom: 3px;'>";
for(var i=1;i<a.length;i++){
result += "<div id='pl"+a[i].id+"' style='text-indent:1em;background-color: #eeeeee;border: 1px solid #000000;margin-left: 3px;margin-right: 3px;margin-top: 3px;margin-bottom: 3px;'>";
};
for(var i=1;i<a.length;i++){
result += "<p>"+a[i].Content+"</p></div>";
};
result += "<p>"+a[0].Content+"<P></div>";
document.getElementById("pl").innerHTML = result;
</script>
教学例子
论坛盖楼回复样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style media="screen">
.commentbox{
border: 1px solid #ccc;
padding: 10px;
margin: 2px;
}
</style>
</head>
<body>
<div class="commentbo">
盖楼!!盖楼!!盖楼
<div class="commentbox">
盖楼!!盖楼!!盖楼
<div class="commentbox">
盖楼!!盖楼!!盖楼
</div>
</div>
</body>
</html>
mongodb数据库评论数据结构
gid每个商品的ID
status:数据的状态,可以使删除,可以使隐藏
<script>
//查询评论
function getDiscuss(){
$.ajax({
url:'http://192.168.20.222:3000/admin/getDiscuss',
data:{gid:goodsID},
dataType:'json',
type:'post',
success:function(data){
var c=data;
var a='<div class="commentsinfo">';
var b='<p class="theauthor">';
var h='</p><span class="commentsnumber">';
var d='</span><p>';
var e='</p></div>';
var g='<div class="comments">';
var str='';
for (var i = 0; i < c.length; i++) {
var xstr='';
var x=c[i]._contents;
}
}
})
}
</script>
发表评论
<script>
function doDiscuss(){
var con=$('#sendM').val();
$.ajax({
url:'http://192.168.20.222:3000/admin/doDiscuss'
data:{content:con, gid:goodsID},
dataType:'json',
type:'post',
success:function(data){
if(data.result =='yes'){
$('#sendM').val('');
getDiscuss();
alter('发表成功')
}else if(data.result=='noLogin'){
$('#hiddenLogin').click();
}
}
})
}
</script>
//获取所有评论
javascript序列化:serialize是一个json对象
//获取评论
export.getDiscuss=function(req,res,next){
goodsModel.getDiscuss(req.body.gid,'discuss',function(result){
if(result !='error'){
res.json(result);
}else{
res.json('error');
}
})
}