Я получаю коллекцию firestore с идентификатором документов, объединенным с данными документов, например:
async function getUsers() {
const users = [];
fb_db.collection("users").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
const data = { ...doc.data(), ...{ id: doc.id }};
if ( data.userid !== undefined && data.userid.length > 0 ) users.push(data);
});
return users;
});
}
//this is the other question's solution
const asyncExample = async () => {
const result = await getUsers()
return result
}
Насколько я понимаю, я должен добавить asyn c в getUsers, сложно, очевидно, не до конца понимаю, почему
Я хочу получить результат в переменной, я пытался реализовать решение этого вопроса, но я не могу получить его работа.
Я пробовал это:
document.addEventListener('DOMContentLoaded', function(e) {
someFunction();
// this doesn't log anything but undefined
;(async () => {
const users = await asyncExample()
console.log(users)
})()
//obviously this doesn't work either, it just logs a promise
the_users = getUsers();
console.log(the_users);
//[THIS SCOPE]
});
Я хочу иметь переменную, содержащую пользователей (в // [ЭТОЙ ОБЪЕМ]), а затем l oop значения и "кое-что"