You are viewing a single comment's thread from:

RE: Hivejs开发实战指南

in #starnote21 days ago

使用递归的方法获取

async function getAllReplies(author, permlink, res=[]) {
  let replies = await hive.api.getContentRepliesAsync(author, permlink)
  let children = []
  replies.forEach(item => {
    res.push(item)
    if(item.children > 0){
      //把得到的子数据塞进 .child 中
      children.push(getAllReplies(item.author, item.permlink, item.child=[]))
    }
  })
  await Promise.all(children)
  return res
}