Ejemplo n.º 1
0
// 迭代栏目
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)
}
Ejemplo n.º 2
0
// 获取子栏目
func (this *categoryRep) GetChildCategories(merchantId, categoryId int) sale.CategoryList {
	var all []*sale.Category = this.GetCategories(merchantId)
	var newArr []*sale.Category = []*sale.Category{}

	var cdt iterator.Condition = func(v, v1 interface{}) bool {
		return v1.(*sale.Category).ParentId == v.(*sale.Category).Id
	}
	var start iterator.WalkFunc = func(v interface{}, level int) {
		c := v.(*sale.Category)
		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.Category{Id: categoryId}, cdt, start, nil, 1)

	return newArr
}