![](/img/trans.png)
[英]I am trying to store value of JSON data in an array from servlet but it shows posts.map is not function
[英]I am trying to get a users from firestore and store them in Map in javascript but for some reasone the map is empty
所以用戶 Object 有 5 個屬性 firstName、lastName、email、password 和 city。
我正在使用 class 用戶中的方法來獲取用戶,該方法是:
getUsersData () {
const usersMap = new Map()
this.users.get().then((data) => {
data.docs.forEach(user=> {
const {email , password} = user.data();
usersMap.set(email,password);
});
});
return usersMap;
}
在 chrome 控制台中返回:
Map(0) {}
[[Entries]]
0: {"mehdiboujid@gmail.com" => "dqdqwdq"}
size: (...)
__proto__: Map
我正在嘗試在 Map 中使用憑據,因為每個用戶都將擁有一個唯一的 email,這將是 map 的關鍵。
如果this.users.get()
是異步的,則必須在返回usersMap
之前await
結果。
async getUsersData() { const usersMap = new Map() await this.users.get().then((data) => { data.docs.forEach(user => { const { email, password } = user.data(); usersMap.set(email, password); }); }); return usersMap; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.