1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| specProps := product.SpecProps spec := models.Spec{} err := json.Unmarshal([]byte(specProps), &spec) if err == nil { sItem := make([]models.SpecChildren, 0) for _, v := range spec.Spec { scItem := make([]models.SpecChildrenItem, 0) for _, vv := range v.Children { if vv.Selected { vv.Selected = false scItem = append(scItem, vv) } } v.Children = scItem sItem = append(sItem, v) } spec.Spec = sItem
data, err := json.Marshal(spec) if err == nil { product.SpecProps = string(data) } }
specProps := product.SpecProps spec := models.Spec{} err := json.Unmarshal([]byte(specProps), &spec) if err == nil { for j := 0; j < len(spec.Spec); j++ { v := &spec.Spec[j] for i := len(v.Children) - 1; i >= 0; i-- { if !v.Children[i].Selected { v.Children = append(v.Children[:i], v.Children[i+1:]...) } } }
specData, err := json.Marshal(spec) if err == nil { product.SpecProps = string(specData) } }
|