Javascript 使用RxJS运算符以角度转换响应数据
我有如下的服务响应Javascript 使用RxJS运算符以角度转换响应数据,javascript,angular,angular-httpclient,Javascript,Angular,Angular Httpclient,我有如下的服务响应 "amount": 3330, "count": 56, "dataObjects": [ { "links": { "self": "http://localhost:4200/api/collection/" }, "id": "W391",
"amount": 3330,
"count": 56,
"dataObjects": [
{
"links": {
"self": "http://localhost:4200/api/collection/"
},
"id": "W391",
"objectNumber": "IN-W391",
"title": "Image 23",
"webImage": {
"guid": "89de22aa-e19f-4c83-87ff-26dd8f319c05",
"width": 1200,
"height": 800,
"url": "http://localhost:4200/api/collection/7qzT0pbclLB7y3fdS1GxzMnV7m3gD3gWnhlquhFaJSn6gNOvMmTUAX3wVlTzhMXIs8kM9IH8AsjHNVTs8em3XQI6uMY=s0"
}
},
{
"links": {
"self": "http://localhost:4200/api/collection/"
},
"id": "W391",
"objectNumber": "IN-W391",
"title": "Image 23",
"webImage": {
"guid": "89de22aa-e19f-4c83-87ff-26dd8f319c05",
"width": 1200,
"height": 800,
"url": "http://localhost:4200/api/collection/7qzT0pbclLB7y3fdS1GxzMnV7m3gD3gWnhlquhFaJSn6gNOvMmTUAX3wVlTzhMXIs8kM9IH8AsjHNVTs8em3XQI6uMY=s0"
}
}
]
}
我所要做的只是检索dataObjects数组,这样我就可以循环遍历它,并将url绑定到webImage下,并在UI中显示它。这是我试过的
组件。ts
ngOnInit() {
this.artistService.GetArtistDetails().pipe(map( response=> response.dataObjects))
.subscribe((artists: any[])=>{
console.log(artists);
});
}
}
public GetArtistDetails(){
return this.httpClient.get(this.REST_API_SERVER);
}
服务.ts
ngOnInit() {
this.artistService.GetArtistDetails().pipe(map( response=> response.dataObjects))
.subscribe((artists: any[])=>{
console.log(artists);
});
}
}
public GetArtistDetails(){
return this.httpClient.get(this.REST_API_SERVER);
}
提前感谢除了A2Ia所说的之外,下面是一个示例代码,可以根据需要工作: stackblitz应用程序:
结果:在您的服务文件中,是否可以将其直接强制转换为模型类型?e、 方法GetArtistDetails():可观察的{//then use.pipe(map(result=>result.dataObjects))}