我正在尝试将响应列表转换为不同类型的对象。
当前进行的HTTP调用返回
Observable<Object1>
我想转换成
{id: string, type: string} (more info below)
getData(): Observable<Object1[]> {
return this.http.get<Object1[]>(this.url);
}
我用这种方式引用这个:
this.getData()
.pipe(
//I understand this can transform each entry into { id: string, type: string } undefined
map(res => res))
.subscribe(res => console.info(res));
对象设置:
class Object1 {
name: string;
setId: string;
date: string;
}
任何关于如何实现这一目标的建议都将受到赞赏。
转换将导致以下object2类型的对象列表:
Object2
{
id: Object1.setId,
type: Object1.name
}
JSON响应
{
"name":"Test1",
"setId":"1",
"date":"3456"
},
{
"name":"Test2",
"setId":"2",
"date":"44556"
}