help_doc_classify.go 964 B

1234567891011121314151617181920212223242526272829303132
  1. package services
  2. import "eta/eta_docs/models/crm"
  3. func helpDocClassifyHaveChild(allNode []*crm.HelpDocClassifyItems, node *crm.HelpDocClassifyItems) (childs []*crm.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 []*crm.HelpDocClassifyItems, node *crm.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. }