我的第一个帖子请求看起来像
this.http.post('http://localhost:8080/api/userfilm/get/', {
name: this.name })
他返回具有名为filmid 的属性的对象数组。我的第二个帖子请求看起来像
this.http.post('http://localhost:8080/api/post/get/', {
filmid: film.filmid })
我真的不知道我怎么能一一做到这一点。例如
getAllPosts() {
return this.http.post('http://localhost:8080/api/userfilm/get/',
{ name: this.name })
.flatMap((film: any) =>
this.http.post('http://localhost:8080/api/post/get/',
{ filmid: film.filmid }))
}
this.getAllPosts().subscribe(response => {
console.log(response);
})
但这不是正确返回
你可以这样实现
this.http.get("https://jsonplaceholder.typicode.com/users")
.map(res => res.json())
.mergeMap((customers: any[]) => {
if (customers.length > 0) {
return Observable.forkJoin(
customers.map((customer: any) => {
return this.http.get('https://jsonplaceholder.typicode.com/users/' + customer.id)
.map((res: any) => {
return res.json();
});
})
);
} else {
return Observable.of([]);
}
}).subscribe(res => console.log(res));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句