Observable.concat和Observable.forkjoin都没有触发 - Ionic 3 with Angular 5

时间:2018-04-21 15:33:28

标签: angular ionic3 angular2-observables

在Ionic中,我试图在循环中调用API以将离线数据上传到服务器。 Observable.concatObservable.forkjoin都没有触发,甚至不打印“Inside Observable”。

1. GetUnSyncTransFromLocal => gets the master data from SQLite
2. GetOrderDetailByOrNo => gets the details of that master from SQLite
3. SaveOrder => calls the service

前两个方法返回的离线数据用于构造对象CompleteOrder

export class CompleteOrder {
    OrderMaster: OrderMaster;
    OrderDetails: OrderDetail[];
}

然后逐个上传订单。

let obserArray = [];
this.kbDb.GetUnSyncTransFromLocal(this.loginid).then(oData => {
      if (oData != undefined && oData.length > 0) {
        for (var so = 0; so < oData.length; so++) {
          this.orderToUpload = new CompleteOrder();
          this.orderToUpload.OrderMaster = oData[so];
          let _orNo = this.orderToUpload.OrderMaster.OrderNumber;
          this.kbDb.GetOrderDetailByOrNo(_orNo).then(dData => {
            if (dData != undefined && dData.length > 0) {
              this.orderToUpload.OrderDetails = dData;
              obserArray.push(Observable.of(this.syncService.SaveOrder(this.orderToUpload)));
            }
        }, aErr => {
            this.salesStatus.push({ UploadMsg: 'Cannot retrieve details for ' + _orNo + ' : ' + aErr });
        });
    }
    Observable.concat(obserArray).subscribe(dataArray => {
        console.log("Inside Observable");
        console.log(JSON.stringify(dataArray));
    }, err => {
            console.log(JSON.stringify(err));
    });
}

请告诉我我缺少的内容或任何其他调用API的方法。

0 个答案:

没有答案