Browse Source

map切片把for改成截取

master v0.5.7
loshiqi 2 years ago
parent
commit
a18c222878
1 changed files with 11 additions and 10 deletions
  1. +11
    -10
      map.go

+ 11
- 10
map.go View File

@ -263,16 +263,17 @@ func MapSort(order, val, val_type string, MapDate []map[string]interface{}) ([]m
return res, nil
}
func MapPage(pageNum, pageSize int, MapDate []map[string]interface{}) []map[string]interface{} {
list := []map[string]interface{}{}
stat := (pageNum - 1) * pageSize
end := stat + pageSize - 1
for k, v := range MapDate {
if k >= stat && k <= end {
list = append(list, v)
}
if k > end {
break
}
end := stat + pageSize
count := len(MapDate)
if stat >= count {
return []map[string]interface{}{}
}
if end >= count {
end = count
}
if stat < 0 || end < 0 {
return []map[string]interface{}{}
}
return list
return MapDate[stat:end]
}

Loading…
Cancel
Save