treeItems 获取子树
(parentId string, parentMap map[string][]*catalogue.Catalogue)
| 655 | |
| 656 | // treeItems 获取子树 |
| 657 | func treeItems(parentId string, parentMap map[string][]*catalogue.Catalogue) []*catalogue_dto.Item { |
| 658 | items := make([]*catalogue_dto.Item, 0) |
| 659 | if _, ok := parentMap[parentId]; ok { |
| 660 | for _, v := range parentMap[parentId] { |
| 661 | childItems := treeItems(v.Id, parentMap) |
| 662 | items = append(items, &catalogue_dto.Item{ |
| 663 | Id: v.Id, |
| 664 | Name: v.Name, |
| 665 | Children: childItems, |
| 666 | Sort: v.Sort, |
| 667 | }) |
| 668 | } |
| 669 | } |
| 670 | sort.Slice(items, func(i, j int) bool { |
| 671 | return items[i].Sort < items[j].Sort |
| 672 | }) |
| 673 | return items |
| 674 | } |