javascript - 在 Angular rxjs 中转换 API 响应
问题描述
嗨,我收到了来自 API 的回复:
{
"records":[
{
"id":1,
"motivazione":"",
"autorizzazione":false,
}
]
}
我如何像这样转换它:
[
{
"id":1,
"motivazione":"",
"autorizzazione":false,
},
]
谢谢
约瑟夫
解决方案
You can use the map operator in rxjs to transform your data. More precisely if you only want the records property from your response object you can do that as following:
import { map } from 'rxjs/operators';
transformData(){
this.http.get(url).pipe(map((target: any) => target.records)).subscribe((data) => {
console.log(data);
})}
这将仅从您的响应对象返回记录属性。
推荐阅读
- python - 过早关闭嵌套的异步生成器
- docker - Docker 只向 localhost 公开一个端口
- java - idk 如何读取文件中的字符符号,而我不会遇到空格(Java)
- omnet++ - 获取车辆ID
- amazon-web-services - 使用控制台将大文件上传到 s3 花费太多时间
- android - 如何在 BroadcastReceiver 中唤醒设备?
- imagemagick - ImageMagick 将阴影添加到被覆盖的透明 png
- c++ - 如何从控制台 C++ 捕获输出(来自 cout)
- python-3.x - 余弦相似度很慢
- javascript - 使用 Javascript 在 Blogger 上等待页面