哼!问题是 JavaScriptsome方法的等价物是Iterable类上的方法,而不是List. 本List类实现了Iterable,不过,这样我就可以早点发现它,但我想我是在所有这些方法描述丢失。
Dart 的等价some方法称为any:
Iterable<E>bool any(bool test(E element))检查此迭代的任何元素是否满足
test。按迭代顺序检查每个元素,如果其中任何一个使 test 返回 true,则返回 true,否则返回 false。
用法示例:
// The list in which we want to check if there is an item that passes a certain test.
List<String> haystack = [
// It contains some elements...
];
// Just to be explicit in this example, you don't really need it
typedef TestFunc = bool Function(String);
// The test. Just some function that takes an element and returns boolean.
TestFunc isNeedle = (String v) => v.toLowerCase().contains('needle');
bool gotNeedle = haystack.any(isNeedle);
Run Code Online (Sandbox Code Playgroud)