如何对从 firebase 检索到的对象列表进行排序?

How to sort an object list retrieved from fire base?

我是 firebase 的新手,我注意到因为 firebase 并不真正存储数组,所以我不能像排序数组那样对它们进行排序。我在 firebase 中存储了一个包含日期和时间的对象列表,我想根据它们从低到高对其进行排序。

我已检索到数据,但我不知道如何对其进行排序。这是我的数据在 firebase 上的样子:https://imgur.com/a/z9RpJa8

注意:如果可能的话,在对列表进行排序后,我想知道如何对属于同一日期的所有约会进行分组。

Appointments;
constructor(public navCtrl: NavController, public navParams: NavParams, public firebase: FirebaseProvider) {
  this.Appointments = this.firebase.getAppointments();
}

getAppointments() {
  return this.afdb.list('/Apointments/');
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>

<ng-container *ngFor='let a of Appointments|async'>
  <ion-card>
    <button ion-item>
      Time:&nbsp;{{a.Time}}<br/>
      Number of available maids: &nbsp;{{a.NoOfMaids}}
    </button>
  </ion-card>
</ng-container>

  1. Firebase Realtime DB 不允许您执行查询,您可以查看 Firestore,这可能是更好的选择。

  2. 您可以用不同的方式对数据建模以实现这一点 现在您正在存储 Appointments>Id>Data 相反,您可以像 Appointments>Date>Ids>Data 一样存储 这样您就可以直接查询特定日期。

  3. 获取 ref /Appointments 的快照并转换为数组并在本地排序