OrderByChild和equalTo在Ionic 3中不起作用

时间:2018-12-16 12:08:17

标签: javascript firebase firebase-realtime-database ionic3

在我的HTML中

<ion-segment [(ngModel)]="landmarkTag" (ionChange)="changeOption(value)">
      <ion-segment-button value="placesofworship">
        Temples
      </ion-segment-button>
      <ion-segment-button value="museum">
        Museum
      </ion-segment-button>
    </ion-segment>

  <div [ngSwitch]="landmarkTag">
    <ion-list *ngSwitchCase="'placesofworship'">
      <ion-item *ngFor="let chinlandmark of (chinlandmarksRef$ | async)">
          {{chinlandmark.landmarkName}}
      </ion-item>
    </ion-list>

    <ion-list *ngSwitchCase="'museum'">
      <ion-item *ngFor="let chinlandmark of (chinlandmarksRef$ | async)">
          {{chinlandmark.landmarkName}}
      </ion-item>
    </ion-list>
  </div>

在我的TS中

changeOption(landmarkTag)
{
    if (this.landmarkTag == 'placesofworship')
    {
      this.chinlandmarksService.getChinlandmarksOption(this.landmarkTag);
    }
    if (this.landmarkTag == 'museum')
    {
      this.chinlandmarksService.getChinlandmarksOption(this.landmarkTag);
    }
  }

在我的服务TS中

getChinlandmarksOption(landmarkTag)
{
   return this.db.list('chinlandmarksTable', ref => ref.orderByChild('landmarkTag').equalTo(landmarkTag));
}

我的Firebase数据的结构如下:

enter image description here

基于上述代码段,我只能从Firebase检索所有数据,但无法根据“ landmarkTag”对其进行排序。我什至尝试对'equalTo'语句中的地标标签值进行硬编码,但仍然无法检索到它。我不确定是怎么了。请指教..谢谢!

0 个答案:

没有答案