如何过滤地图/访问条目 [英] How can I filter a map / access the entries
本文介绍了如何过滤地图/访问条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Map界面似乎没有以迭代方式提供对条目的访问,也未公开用于过滤条目的where方法。我想念什么吗?有一个简单的解决方法吗?
The Map interface doesn't seem to provide access to the entries as an iterable, nor does it expose a where method to filter entries. Am I missing something? Is there a simple workaround?
例如
Map map;
final filteredMap = map.where((k, v) => k.startsWith("foo"));
推荐答案
Dart 2.0.0已添加 removeWhere
可用于过滤Map实体。给定您的示例,您可以将其应用为:
Dart 2.0.0 added removeWhere
which can be used to filter Map entities. Given your example, you could apply this as:
Map map;
final filteredMap = Map.from(map)..removeWhere((k, v) => !k.startsWith("foo"));
这不是您要求的位置
方法,但是通过这种方式过滤Map实体当然是可行的。
It's not the where
method you asked for, but filtering Map entities is certainly doable this way.
这篇关于如何过滤地图/访问条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文