Dart - 如何排序地图的键 [英] Dart - How to sort Map's keys

查看:765
本文介绍了Dart - 如何排序地图的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Dart中排序Map的键有问题。

I have question in sorting Map's key in Dart.

Map<String, Object> map = new Map();

如何在地图中排序键?

How can I sort the keys in map? or Sort the Iterable map.keys.

推荐答案

如果你想要一个排序的 List 的地图键:

If you want a sorted List of the map's keys:

var sortedKeys = map.keys.toList()..sort();

您可以选择将自定义排序函数传递给 List.sort 方法。

You can optionally pass a custom sort function to the List.sort method.

最后,我建议使用 Map< String,dynamic> code> Map< String,Object>

Finally, might I suggest using Map<String, dynamic> rather than Map<String, Object>?

这篇关于Dart - 如何排序地图的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆