我如何循环遍历 firestore 中的对象数组(数组联合对象)

how can i loop through array of objects from firestore (array union objects)

我有一个注释数组字段,它在 firestore 数据库中有两个对象。

它 returns 在控制台中是这样的:

我尝试使用下面的代码遍历数组,但没有成功。我究竟做错了什么?

HTML:

<ion-card style="margin-top: 10px !important;" *ngFor ="let comment of comments">   
    <ng-container *ngFor="let item of comment?.comments">
       <div style="color: black"><h6>{{item?.comment}}</h6></div>

    </ng-container>
</ion-card>

TS:

comments: any = [];

getData(){
  this.route.data.subscribe(routeData => {
    let data = routeData['data'];
    this.comments = [];
    if (data) {
      this.item = data;
      this.image = this.item.image;  
      this.comments.push(this.item.comments)
      console.log( this.comments ) 
    }
  })   
}

看来你应该这样做:

<ion-card style="margin-top: 10px !important;" *ngFor="let comment of comments">   
    <ng-container *ngFor="let item of comment">
       <div style="color: black"><h6>{{item?.comment}}</h6></div>

    </ng-container>
</ion-card>

所以在内部循环中 comment 而不是 comment?.comments