1 回答

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超21個(gè)贊
我想您可以將組作為指針傳遞給 addItem 函數(shù),并忽略該函數(shù)的返回值
有一點(diǎn)像
func addItem(list *Group, newItem string, path string) Group {
? ? var currentGroup *Group = list
? ? if path == "" {
? ? ? ? currentGroup.Item = append(currentGroup.Item, newItem)
? ? } else {
? ? ? ? for _, elem := range strings.Split(path, "/") {
? ? ? ? ? ? in, index := in(elem, currentGroup.Groups)
? ? ? ? ? ? if in {
? ? ? ? ? ? ? ? currentGroup = ¤tGroup.Groups[index]
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? currentGroup.Item = append(currentGroup.Item, newItem)
? ? }
? ? return *currentGroup
}
- 1 回答
- 0 關(guān)注
- 121 瀏覽
添加回答
舉報(bào)