使用userId获取用户信息

编程入门 行业动态 更新时间:2024-10-17 02:50:15
本文介绍了使用userId获取用户信息-Angular Firestore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有2个不同的收藏集:

I've got 2 different collections:

  • 用户:姓名,电子邮件和头像(来自其社交网络)
  • 配方:用户可以创建的文档.它还包含userId及其对先前集合的引用
  • Users: name, email and avatar (taken from their social network)
  • Recipes: documents that the user can create. It also contains userId with their references to previous collection

要在我的页面上显示这些食谱,我使用:

To display these recipes on my page I use:

this.recipes = collection.snapshotChanges().map(actions => { return actions.map(action => ({ $id: action.payload.doc.id, ...action.payload.doc.data() })); });

并且:

<ion-card *ngFor="let recipe of recipes | async; let i = index"> ...

同时获得用户头像和姓名的最佳方法是什么?

What's the best way to get also the user avatar and name?

推荐答案

尝试此代码

this.recipes = collection.snapshotChanges().map(actions => { return actions.map(a => { const data = a.payload.doc.data(); const id = a.payload.doc.id; //this.afs.collection('users') is the ref to users collection, yours should be different return this.afs.collection('users').doc(data.userId).snapshotChanges().map(userActions=>{ return userActions.payload.data(); }).map(user=>{ return { id:id, userName:user.name, ...data }; }) }); }).flatMap(merge => ObservablebineLatest(merge)).map(data => { return [].concat(...data).map(d => { return d; }) });

更多推荐

使用userId获取用户信息

本文发布于:2023-11-13 22:40:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585517.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户信息   userId

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!