![](/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.