firestore以.where顺序返回数组

时间:2018-06-24 13:54:58

标签: typescript angular5 google-cloud-firestore

在angular 5 TypeScript中,我想通过数组从firestore中显示图表中的数据,我已成功将数据加载到图表中,但是firestore乱序返回了数组,然后数据错误地到达了图表中。我该怎么办 ? 仪表板中的代码。ts:

    /*an empty arrays*/
public lineChartDataArray = [];
  public lineChartData: Array<any> = [
    { data: [this.lineChartDataArray], label: 'כמות לקוחות' }];

  public lineChartDateTime: Array<any>;





/*take the days of the month and check if the dates found in firestore*/
async setChartOneMonth(startDate, diffDays) {
    var currentDate = this.fromDate;
    var days;
    for (let i = 0; i <= diffDays - 1; i++) {
      currentDate = new Date(currentDate.setDate(startDate.getDate() + i));
      days = this.datePipe.transform(currentDate, 'dd/MM/yyyy');
      var date = this.datePipe.transform(currentDate, 'yyyy/MM/dd');
      this.lineChartDateTime.push(days);
      this.clientService.numClientByDate(date).forEach(async data => {
        this.lineChartDataArray.push(data.length);

      })
    }
    let result = await this.setChartTable(this.lineChartDataArray);
  }




/*axisY by the array that the funstion get*/
 setChartTable(lineChartCompletedArray) {
    var p = new Promise((resolve, reject) => {
      setTimeout(() => {
        this.lineChartData = [
          { data: lineChartCompletedArray, label: 'client quantity' }];
      }, 1000);
    })
    return p;`

  }




client.service.ts
/*returns the dates in the firestore*/
 numClientByDate(createDate) {
    return this.afs.collection('Members/' + this.seission.retrieve("user") + '/Clients/', ref => {
      // Compose a query using multiple .where() methods
      return ref
        .where('createDate', '==', createDate)
        .orderBy('createDateByDay')

    }).valueChanges();

  }

0 个答案:

没有答案