1
0
mirror of https://github.com/beego/bee.git synced 2024-11-10 15:00:54 +00:00

refactor reflection template for models

This commit is contained in:
ZhengYang 2014-08-06 10:49:26 +08:00
parent 6a7428b3aa
commit f879d728c8

View File

@ -684,19 +684,11 @@ func GetAll{{modelName}}(query map[string]string, fields []string, sortby []stri
} }
} else { } else {
// trim unused fields // trim unused fields
fieldMap := make(map[string]interface{})
for _, v := range fields {
fieldMap[v] = true
}
for _, v := range l { for _, v := range l {
m := make(map[string]interface{}) m := make(map[string]interface{})
s := reflect.Indirect(reflect.ValueOf(v)) val := reflect.ValueOf(v)
typeOfS := s.Type() for _, fname := range fields {
for i := 0; i < s.NumField(); i++ { m[fname] = val.FieldByName(fname).Interface()
f := s.Field(i)
if _, ok := fieldMap[typeOfS.Field(i).Name]; ok {
m[typeOfS.Field(i).Name] = f.Interface()
}
} }
ml = append(ml, m) ml = append(ml, m)
} }