// SetAllSliceLengths sets the length of all slices in document. func SetAllSliceLengths(document interface{}, length int) { Visit(document, VisitorFunc( func(data *MetaData) error { if data.Kind == SliceKind && data.Value.Len() != length { data.Value.Set(reflection.SetSliceLengh(data.Value, length)) } return nil }, )) }
func (self *setPostValuesStructVisitor) BeginIndexedFields(indexedFields *model.MetaData) error { if indexedFields.Kind == model.SliceKind && indexedFields.Value.CanSet() && !self.form.IsFieldExcluded(indexedFields, self.ctx) { if lengthStr := self.ctx.Request.FormValue(indexedFields.Selector() + ".length"); lengthStr != "" { length, err := strconv.Atoi(lengthStr) if err != nil { panic(err) } if length != indexedFields.Value.Len() { indexedFields.Value.Set(reflection.SetSliceLengh(indexedFields.Value, length)) mongo.InitRefs(self.formModel) } } } return nil }