feat: finish renderComment

feat/fix/umd
SukkaW 7 years ago
parent 10e66a97f9
commit 2a4a918259

@ -295,6 +295,12 @@ function DisqusJS(config) {
return commentLists;
}
/*
* renderCommentData(data) - 渲染评论列表
*
* @param {Object} data - getComment() 获取到的 JSON
*/
let renderComment = (data) => {
/*
* processData(data) - 处理评论列表
*
@ -358,22 +364,45 @@ function DisqusJS(config) {
return html;
}
let childrenComments = (data) => {
var nesting = data.nesting,
children = (data.children || []);
if (!children) {
return;
}
/*
* renderCommentData(data) - 渲染评论列表
*
* @param {Object} data - getComment() 获取到的 JSON
*/
let renderComment = (data) => {
var html = '';
let html = (() => {
// 如果当前评论嵌套数大于 4 则不再右移
if (nesting < 4) {
return '<ul class="dsqjs-post-list dsqjs-children">';
} else {
return '<ul class="dsqjs-post-list">';
}
})();
html += children.map((comment) => {
comment = processData(comment);
comment.nesting = nesting + 1;
return `<li data-id="comment-${comment.comment.id}">${renderPostItem(comment.comment)}${childrenComments(comment)}</li>`;
});
html += '</ul>';
if (html.length !== 0) {
return html;
} else {
return;
}
}
let html = ''
data = parseCommentData(data);
data.map((comment) => {
html += data.map((comment) => {
comment = processData(comment);
console.log(comment)
html += `<li data-id="comment-${comment.comment.id}">${renderPostItem(comment.comment)}${childrenComments(s)}</li>`;
})
return `<ul class="dsqjs-post-list"><li data-id="comment-${comment.comment.id}">${renderPostItem(comment.comment)}${childrenComments(comment)}</li></ul>`;
});
console.log(html)
}

Loading…
Cancel
Save