help_doc_classify.go 996 B

123456789101112131415161718192021222324252627282930313233
  1. package data
  2. import "hongze/hz_crm_api/models/help_doc"
  3. func helpDocClassifyHaveChild(allNode []*help_doc.HelpDocClassifyItems, node *help_doc.HelpDocClassifyItems) (childs []*help_doc.HelpDocClassifyItems, yes bool) {
  4. for _, v := range allNode {
  5. if v.ParentId == node.ClassifyId {
  6. childs = append(childs, v)
  7. }
  8. }
  9. if len(childs) > 0 {
  10. yes = true
  11. }
  12. return
  13. }
  14. func HelpDocClassifyItemsMakeTree(allNode []*help_doc.HelpDocClassifyItems, node *help_doc.HelpDocClassifyItems) {
  15. childs, _ := helpDocClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
  16. if len(childs) > 0 {
  17. node.Children = append(node.Children, childs[0:]...) //添加子节点
  18. for _, v := range childs { //查询子节点的子节点,并添加到子节点
  19. _, has := helpDocClassifyHaveChild(allNode, v)
  20. if has {
  21. HelpDocClassifyItemsMakeTree(allNode, v) //递归添加节点
  22. } else {
  23. v.Children = nil
  24. }
  25. }
  26. } else {
  27. node.Children = nil
  28. }
  29. }