package services import "eta/eta_forum_admin/models/help_doc" func helpDocClassifyHaveChild(allNode []*help_doc.HelpDocClassifyItems, node *help_doc.HelpDocClassifyItems) (childs []*help_doc.HelpDocClassifyItems, yes bool) { for _, v := range allNode { if v.ParentId == node.ClassifyId { childs = append(childs, v) } } if len(childs) > 0 { yes = true } return } func HelpDocClassifyItemsMakeTree(allNode []*help_doc.HelpDocClassifyItems, node *help_doc.HelpDocClassifyItems) { childs, _ := helpDocClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回 if len(childs) > 0 { node.Children = append(node.Children, childs[0:]...) //添加子节点 for _, v := range childs { //查询子节点的子节点,并添加到子节点 _, has := helpDocClassifyHaveChild(allNode, v) if has { HelpDocClassifyItemsMakeTree(allNode, v) //递归添加节点 } else { v.Children = nil } } } else { node.Children = nil } }