- 初始化-获取循环中的异步数据
// 初始化
onLoadPage(info: any, dept: any = null, newInfo: any = null) {
if (info && info.ID) {
this._service.getEdit(info.ID).success((d) => {
$.extend(this.editInfo, d);
// 查询岗位列表
if (this.editInfo.Positions.length > 0) {
const unitPositions = [];
Promise.all(
// 添加 async 和 await
this.editInfo.Positions.map(async (o) => {
let dept;
if (o && o.UnitID) {
await this.loadNode(o.UnitID).then((data) => {
dept = data.find((d) => d.id === o.DeptID);
});
}
return dept ? this.pushPosition(unitPositions, dept, o) : Promise.resolve();
})
).then((d) => {
this.editInfo.Positions = unitPositions;
});
}
});
});
}
/**
* 职位
*
*/
pushPosition(positionUsers: any[], dept: any, positionUser: any = null) { }