从firestore onSnapshot返回后,数据未渲染

发布于 2025-02-08 09:40:59 字数 1997 浏览 1 评论 0原文

我在这里使用离子/角前端。我的数据正确地来自Firestore。在对Firestore文件进行了更改后,它也会返回。

但是,数据永远不会呈现到ion-content。它确实正确地登录到控制台。这使我相信我在离子/角度做错了。

模板文件

<ion-content [fullscreen]="true" style="text-align: center;" *ngIf="!this.isLoading">
    <ion-item *ngFor="let team of currentTeams; let index" [color]="team.color" style="margin: 10px;">
      <p>{{index}}</p>
      <h1 slot="start" style="height: 3.5rem;">{{ team.name }}</h1>
      <br />
      <div id="controls" slot="end">
        <ion-icon style="margin: 0 20px" name="remove-circle" (click)="decrementTeamScore(team)"></ion-icon>
        <span>{{ team.score }}</span>
        <ion-icon style="margin: 0 20px" name="add-circle" (click)="incrementTeamScore(team)"></ion-icon>
      </div>
    </ion-item>
</ion-content>

类文件

    this.isLoading = true;
    this.gameId = this.route.snapshot.params.id;
    if(this.gameId) {
      const result = await this.getGame();
      if(result) {
        await this.getTeams();
      }
    }
    this.isLoading = false;
  }
  public async getTeams() {
    const teamRef = this.teamsCollection.ref;
    const teamsByGameIdQuery = teamRef.where('gameId', '==', this.currentGame.docID).orderBy('score', 'desc');
    onSnapshot(teamsByGameIdQuery, (snapshot) => {
      const teams: ITeam[] = [];
      snapshot.docs.forEach((doc) => {
        teams.push({ ...doc.data(), id: doc.id});
        this.currentTeams = teams;
      });
      console.log(this.currentTeams);
    });
  }

还包括我从Firestore返回的控制台数据。

这是当前屏幕的屏幕截图

I am using an Ionic/Angular frontend here. My data comes back from Firestore correctly. It also comes back after a change has been made to the firestore document.

However, the data never renders to the ion-content. It does log to the console correctly. This leads me to believe I am doing something wrong with Ionic/Angular.

The template file

<ion-content [fullscreen]="true" style="text-align: center;" *ngIf="!this.isLoading">
    <ion-item *ngFor="let team of currentTeams; let index" [color]="team.color" style="margin: 10px;">
      <p>{{index}}</p>
      <h1 slot="start" style="height: 3.5rem;">{{ team.name }}</h1>
      <br />
      <div id="controls" slot="end">
        <ion-icon style="margin: 0 20px" name="remove-circle" (click)="decrementTeamScore(team)"></ion-icon>
        <span>{{ team.score }}</span>
        <ion-icon style="margin: 0 20px" name="add-circle" (click)="incrementTeamScore(team)"></ion-icon>
      </div>
    </ion-item>
</ion-content>

The class file

    this.isLoading = true;
    this.gameId = this.route.snapshot.params.id;
    if(this.gameId) {
      const result = await this.getGame();
      if(result) {
        await this.getTeams();
      }
    }
    this.isLoading = false;
  }
  public async getTeams() {
    const teamRef = this.teamsCollection.ref;
    const teamsByGameIdQuery = teamRef.where('gameId', '==', this.currentGame.docID).orderBy('score', 'desc');
    onSnapshot(teamsByGameIdQuery, (snapshot) => {
      const teams: ITeam[] = [];
      snapshot.docs.forEach((doc) => {
        teams.push({ ...doc.data(), id: doc.id});
        this.currentTeams = teams;
      });
      console.log(this.currentTeams);
    });
  }

Also including the console data that I am getting back from Firestore.
Console Data

And here is a screenshot of the current screen
Picture of current screen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空袭的梦i 2025-02-15 09:40:59

好的,我看到,始终会出现错误的问题,我只需删除HTML标签(P,HR,DIV),然后使用离子自己的组件,例如离子贴,离子卡等。

Ok I see, always this errors cames to me, I just remove HTML tags (p, hr, div) and use Ionic own components, like ion-title, ion-card, and so on.

Find more on https://ionicframework.com/docs/components

Thanks !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文