【发布时间】:2021-01-23 21:19:37
【问题描述】:
如何对包含对象的列表进行排序,以便对象的属性与 dart 中的不同列表匹配?
class Example {
String _id;
String get id => _id;
}
List examples = [Example(id: 'hey'), Example(id: 'foo'), Example(id: 'baa')]
List ids = ['foo', 'baa', 'hey']
print(examples.sortBy(ids)) ???????
OUTPUT:
[Example(id: 'foo'), Example(id: 'baa'), Example(id: 'hey')]
【问题讨论】:
-
您可以将
ids的列表映射到Examples的列表,而不是排序