1.递归法:
Title.comment-box{
margin-left: 20px;
}
$(function () {
bindCommentEvent();
});
function bindCommentEvent() {
$('.com').click(function () {
var news_id = $(this).attr('news_id');
var _this = $(this);
$.ajax({
url: '/comment/',
type: 'GET',
data: {news_id: news_id},
dataType: "html",
success:function (arg) {
//create_tree(arg, _this);
console.log(arg);
_this.after(arg);
}
})
})
}
function diGui(children_list){
var html = "";
$.each(children_list,function (ck,cv) {
var b = '
b+= cv.content + "
";b += diGui(cv.children);
b += "
html += b;
});
return html;
}
function create_tree(data,$this) {
var html = '
$this.after(html);
}
标签:function,前端,多级,children,html,id,arg,var,代码
来源: https://www.cnblogs.com/qvpenglou/p/11580894.html
$.each(data,function (k,v) {
var a = '
a+= v.content + "
";// 创建自评论
a += diGui(v.children);
a+= "
html += a;
});
html += "