作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 MappedListIterable
比我知道的要排序
当调用排序方法时,我得到了
EXCEPTION: NoSuchMethodError: Class 'MappedListIterable' has no instance method 'sort'. Receiver: Instance of 'MappedListIterable' Tried calling: sort(Closure: (dynamic, dynamic) => dynamic)
最佳答案
你在调用 .map(f) 后得到一个 MappedListIterable
在 Iterable
上。
Iterable class没有 sort()
方法。这个方法在List .
因此,您首先需要通过调用 .toList()
从 MappedListIterable
中获取一个 List
。
var i = [1, 3, 2].map((i) => i + 1);
// i is a MappedListIterable
// you can not call i.sort(...)
var l = i.toList();
l.sort(); // works
或者在一行中(代码高尔夫):
var i = [1, 3, 2].map((i) => i + 1).toList()..sort();
关于dart - 如何在 Dart 中对 MappedListIterable 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41303656/
我是一名优秀的程序员,十分优秀!