【发布时间】:2021-03-14 19:43:11
【问题描述】:
在我的情况下,获取数据但数据没有根据我想要的请求进行排序,当我调用第一个 HTTP 请求时,它首先将值分配回我的数组,然后移动到下一个 API 调用,但在这种情况下,数据未排序或未将正确的 id 分配给我的数组。
this.imagesdataarray.forEach(imagedata => {
imagedata.imagesnamearray.forEach(imagename => {
const fd = new FormData();
fd.append('userID', this.userid );
fd.append('projectID', imagedata.projectid);
fd.append('id', imagename.imageid);
fd.append('formFiles', imagename.image);
this.http
.post('http://api.interiordesigns2020.com/api/services/app/ImageProject/CreateProjectImages', fd)
.subscribe( async (res) => {
imagename.imageid = await res.result;
});
})
});
【问题讨论】:
-
我不明白你为什么在这里使用 async/await。 Angular HTTPClient 为它的每个请求(post、put、delete...)返回一个 observable。你只需要订阅它。请尝试从您的代码中删除 async 和 await 。另外我建议阅读一些关于 rxjs 的内容。
标签: javascript angular typescript http asp.net-core