我有一个 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/