【发布时间】:2021-07-15 10:55:56
【问题描述】:
嘿伙计们,我对此有点陌生,但我会尽我所能解释它,所以我使用一个函数来返回一个承诺,我的代码看起来像这样
getAccounts(email) {
return new Promise((resolve, reject) => {
usersCollection.where('email', '==', email).where('userType', 'in', ['Admin', 'Superuser'])
.get()
.then(async querySnapshot => {
const accounts = [];
await querySnapshot.forEach(async account => {
let accountData = await account.data();
accountData.id = accountData.userType;
if (accountData.userType === 'Admin') {
const adminObj = new Admin();
const adminData = await adminObj.getAdminDetails();
accountData = { ...accountData, ...adminData };
}
accountData.uid = authId;
await accounts.push(accountData);
});
resolve(accounts);
});
});
}
我目前有两个帐户,一个是管理员,另一个是超级用户,问题是在获取 adminData 之前已解决的承诺,可能是什么问题?
【问题讨论】:
标签: javascript firebase google-cloud-firestore async-await es6-promise