Пример #1
0
// 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(utils.SetSliceLengh(data.Value, length))
			}
			return nil
		},
	))
}
Пример #2
0
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.Error())
			}
			if length != indexedFields.Value.Len() {
				indexedFields.Value.Set(utils.SetSliceLengh(indexedFields.Value, length))
				mongo.InitRefs(self.formModel)
			}
		}
	}
	return nil
}
Пример #3
0
func (self *setPostValuesStructVisitor) BeginSlice(slice *model.MetaData) error {
	if slice.Value.CanSet() && !self.form.IsFieldExcluded(slice) {
		if lengthStr := self.context.Request.FormValue(slice.Selector() + ".length"); lengthStr != "" {
			length, err := strconv.Atoi(lengthStr)
			if err != nil {
				panic(err.Error())
			}
			if length != slice.Value.Len() {
				slice.Value.Set(utils.SetSliceLengh(slice.Value, length))
				mongo.InitRefs(self.formModel)
			}
		}
	}
	return nil
}