RE: RE: SteemJS中文手册
You are viewing a single comment's thread from:

RE: SteemJS中文手册

Words
42
Reading
1 min
Listen
Play
7y

如果某篇文章的回复还有子回复的话,那就要用递归来获取所有的父子回复,判断的参数是: item.children

//某篇文章的回复
steem.api.getContentReplies(author, permlink, function(err, result) {
  console.log(err, result)
})

eg:
async function getReplies(author, permlink, res=[]) {
  let replies = await _this.steem.api.getContentRepliesAsync(author, permlink)
  let children = []
  replies.forEach(item => {
    res.push(item)
    if(item.children > 0){
      //把得到的子数据塞进 .child 中
      children.push(getReplies(item.author, item.permlink, item.child=[]))
    }
  })
  await Promise.all(children)
  return res
}
getReplies(author, permlink)
  .then(res => {
    // console.log(777, res)
    _this.replies = res
  })