// 迭代栏目 func WalkCategory(cs []*sale.ValueCategory, v *sale.ValueCategory, start iterator.WalkFunc, over iterator.WalkFunc) { var condition iterator.Condition = func(v, v1 interface{}) bool { return v1.(*sale.ValueCategory).ParentId == v.(*sale.ValueCategory).Id } var arr []interface{} = make([]interface{}, len(cs)) for i, v := range cs { arr[i] = v } iterator.Walk(arr, v, condition, start, over, 0) }
// 获取子栏目 func (this *saleRep) GetChildCategories(partnerId, categoryId int) []*sale.ValueCategory { var all []*sale.ValueCategory = this.GetCategories(partnerId) var newArr []*sale.ValueCategory = []*sale.ValueCategory{} var cdt iterator.Condition = func(v, v1 interface{}) bool { return v1.(*sale.ValueCategory).ParentId == v.(*sale.ValueCategory).Id } var start iterator.WalkFunc = func(v interface{}, level int) { c := v.(*sale.ValueCategory) if c.Id != categoryId { newArr = append(newArr, c) } } var arr []interface{} = make([]interface{}, len(all)) for i, _ := range arr { arr[i] = all[i] } iterator.Walk(arr, &sale.ValueCategory{Id: categoryId}, cdt, start, nil, 1) return newArr }