在此代码中,我想在处理到下一行之前在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))))));
}