简体   繁体   English

如何在可观察的 Firebase 变量中分配 SnapshotChanges?

[英]How Can I assign the SnapshotChanges in a Observable Firebase Variable?

I want to load all the data of a document, but I can not access the id of the document.我想加载文档的所有数据,但我无法访问文档的 id。 When i print the object this.ressobj the id is visible, but when i put the ressobj.id_doc in the card the id id of the document is not visible.当我打印对象 this.ressobj 时,id 是可见的,但是当我将 ressobj.id_doc 放入卡片时,文档的 id id 不可见。

 this.ResColeccion = this.resser.getSpecificlistRestaurants(this.id); this.ResObservable$ = this.ResColeccion.snapshotChanges().subscribe(usuariolista =>{ this.ressobj=usuariolista.map(res =>{ return{ nombre:res.payload.doc.data().nombre, logo:res.payload.doc.data().logo, descripcion:res.payload.doc.data().descripcion, portada:res.payload.doc.data().portada, idadmin:res.payload.doc.data().idadmin, id_doc:res.payload.doc.id } }); console.log(this.ressobj); });

HTML CODE HTML代码

 <ion-card *ngFor="let ressobj of ResObservable$ | async " [routerLink]="['/opcionesrestaurante',ressobj.id_doc]" > <img src="{{ressobj.portada}}"> <ion-card-content> <ion-card-title> <h1>{{ressobj.nombre}}</h1> </ion-card-title> <p>{{ressobj.descripcion}}</p> </ion-card-content> </ion-card>

Thanks for your help谢谢你的帮助

Not tested but I've used something like that for my angularfire2 projects:未经测试,但我在我的 angularfire2 项目中使用了类似的东西:

Getting a document:获取文档:

const ResObservable$ = () => {
        return this.ResColeccion
          .snapshotChanges()
          .pipe(
            map(actions => {
              const data = actions.payload.data() as any;
              const uid = actions.payload.id;
              return { uid, ...data};
            })
          );
    }

ResObservable$.subscribe(item => console.log(item)) // or use async

Getting a collection:获取集合:

const ResObservable$ = () => {
    return this.ResColeccion
      .snapshotChanges()
      .pipe(
        map(actions => {
          return actions.map(a => {
            const data = a.payload.doc.data() as any;
            const uid = a.payload.doc.id;
            return { uid, ...data };
          });
        })
      );
}

ResObservable$.subscribe(items => console.log(items)) // or use async pipe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 S3 存储桶的原始名称分配给变量,然后使用该变量 - How can I assign the raw Name of an S3 bucket to a variable and then use that variable AngularFire firestore get / snapshotchanges / valuechanges 对 observable 的操作不是异步的? - AngularFire firestore get / snapshotchanges / valuechanges action on observable is not async? 仅当文件完全上传到 Firebase 存储时,如何才能从此方法返回 Observable? - How can return an Observable from this method only when a file is completely uploaded into Firebase Storage? 我如何在 firebase 中使用按日期排序 - How can i use order by date in firebase 如何将 static IP 分配给我的 EKS 服务? - How can I assign a static IP to my EKS service? 找不到变量:firebase - can't find variable : firebase 如何使用 snapshotChanges() 方法获取键值和过滤数据? - How to use snapshotChanges() method to get both key value and filter the data? 如何从 Firebase 中删除记录? - How I can Delete Record from Firebase? 如何将字符串 Arraylist 存储到 Firebase 中? - How can I store an String Arraylist into Firebase? 如何创建 firebase 用户帐户 - How can I create firebase user account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM