【发布时间】:2017-10-05 06:41:30
【问题描述】:
我的数据是这样的:
{
"five": {
"group": {
"one": {
"order": 2
},
"six": {
"order": 1
}
},
"name": "Filbert",
"skill": "databases"
},
"four": {
"group": {
"three": {
"order": 2
},
"two": {
"order": 1
}
},
"name": "Robert",
"skill": "big data"
},
"one": {
"name": "Bert",
"skill": "data analysis"
},
"seven": {
"name": "Colbert",
"skill": "data fudging"
},
"six": {
"name": "Ebert",
"skill": "data loss"
},
"three": {
"name": "Gilbert",
"skill": "small data"
},
"two": {
"name": "Albert",
"skill": "non data"
}
}
我正在使用以下功能:
Future retrieve(String id) async {
Map employeeMap = await employeeById(id); //#1
if (employeeMap.containsKey("group")) { //#2
Map groupMap = employeeMap["group"];
Map groupMapWithDetails = groupMembersWithDetails(groupMap); #3
// above returns a Mamp with keys as expected but values
// are Future instances.
// To extract values, the following function is
// used with forEach on the map
futureToVal(key, value) async { // #4
groupMapWithDetails[key] = await value;
}
groupMapWithDetails.forEach(futureToVal); // #4
}
return groupMapWithDetails;
}
- 我从数据库 (Firebase) 访问一名员工(以 a
Map) - 如果员工是领导者(有一个关键的“组”)
- 我通过调用单独的函数从数据库中获取组中每个员工的详细信息。
- 由于该函数返回一个映射,其值是
Future的实例,我想从中提取实际值。为此,在地图上调用forEach。 但是,我只将 Future 的实例作为值。
如何获得实际值?
【问题讨论】:
标签: dart dart-async