我想停止执行,直到this.conn.getUserByAlternateNumber完成工作并返回一个值

时间:2019-01-04 11:34:20

标签: javascript async-await angular-promise

在此代码中,我想在处理到下一行之前在where对象中设置值,但仅在this.conn.getUserByAlterNumber之后执行到if(this.doctorFilter && this.doctorFilter.length),而无需等待来自函数的响应,因此this.conn.getOrders会获得一个空白对象来代替位置,并且我的过滤器不起作用,如何停止执行,直到this.conn.getUserByAlternateNumber返回值。

loadMore(offset: number): Promise<any> {
    let where: any = {};
    this.filters.forEach((item: any) => {
      if (item.key === 'alternateNumber') {
        this.conn.getUserByAlternateNumber(item.value)
          .then((user: any) => {
            where['contactName'] = user[0].attributes.PatientName;
            console.log(where,'>>>>>');
          });
      } else {
        (where[item.key] = item.value);
      }
    });
    if (this.doctorFilter && this.doctorFilter.length) {
      where.allocatedDoctor = this.doctorFilter;
    }
    console.log(where);
     return this.conn.getOrders({
      where,
      include: ['user', 'allocatedDoctor'],
      limit: this.ui.grid.pageSize,
      asc: this.OrderAsc,
      offset,
    })
      .then((items: any) => this.zone.run(() => Promise.resolve(items.map((i: any) => JSON.parse(JSON.stringify(i))))));
  }

0 个答案:

没有答案