Commit 2dc9d440 authored by zauberstuhl's avatar zauberstuhl

Fix reduceStructField rendering hash instead of array

parent e203bf44
......@@ -21,7 +21,6 @@ import (
"reflect"
"github.com/fatih/structs"
"regexp"
"strconv"
)
// select only a few fields instead of the whole struct
......@@ -65,12 +64,18 @@ func reduceStructField(m map[string]interface{}, fieldParam string) map[string]i
newMap[field] = reduceStructField(model, subField[3])
} else if kind == reflect.Slice {
models := m[field].([]interface{})
newModelMap := make(map[string]interface{}, len(models))
for i, m := range models {
model := m.(map[string]interface{})
newModelMap[strconv.Itoa(i)] = reduceStructField(model, subField[3])
if len(models) > 0 {
var newModelMap []interface{}
for _, m := range models {
model := m.(map[string]interface{})
newModelMap = append(newModelMap, reduceStructField(model, subField[3]))
}
newMap[field] = newModelMap
} else {
// init an empty array, otherwise the
// field will be render with null
newMap[field] = []string{}
}
newMap[field] = newModelMap
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment