包集合实现该
groupBy功能。
对于按日期分组:
import "package:collection/collection.dart";main(List<String> args) { var data = [ {"title": 'Avengers', "release_date": '10/01/2019'}, {"title": 'Creed', "release_date": '10/01/2019'}, {"title": 'Jumanji', "release_date": '30/10/2019'}, ]; var newMap = groupBy(data, (obj) => obj['release_date']); print(newMap);}
release_date要从每个地图条目中删除密钥:
var newMap = groupBy(data, (obj) => obj['release_date']).map( (k, v) => MapEntry(k, v.map((item) { item.remove('release_date'); return item;}).toList()));
更改密钥:
var newMap = groupBy(data, (obj) => obj['release_date']).map( (k, v) => MapEntry(k, v.map((item) => {'name': item['title']}).toList()));
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)