【发布时间】:2017-09-14 14:00:21
【问题描述】:
我有一个问题。在我的程序中,我需要更新服务器上的一些记录,所以我需要通过循环来执行此操作。毕竟我需要从服务器获取新的信息。问题是我如何才能等到所有 http.put 响应为 201?
现在一些代码: 我在服务中有一个更新功能:
public updateDataonServer(rodz: string, id: number, bodyContent: any) {
let body = JSON.stringify(bodyContent);
let headers = new Headers({ 'Content-Type': 'application/json' });
this.currentUser.setHttpHeader(headers);
let options = new RequestOptions({ headers: headers });
return this._http.put(serverAdress + '/rin/' + rodz + '/' + id,
body,
options).map(res => res.status).catch(this.handleError);
}
我在这个函数中使用它:
changeShow(showId: number, oldShow: MpGruppedGroup[]) {
for (var show of oldShow) {
var paramsDict = {
'DAILY_PLAN_GROUP_ID': show.dailyPlanGroupId,
'DAILY_AIRINGS': show.dailyAirings,
'SHOW_ID': showId
};
this.manager.updateDataonServer('MP_GROUPED', show.dailyPlanGroupId, paramsDict).subscribe((data: any) => {
console.log('status ', data);
});
}
// that should be done after all updates return 201 status
this.getShowDayGroups(showId);
}
【问题讨论】: