【发布时间】:2021-01-17 22:49:18
【问题描述】:
例如这是我收到的 json,
{
"events": [...
],
"total": 12341,
"students": [
{
"id": 1,
"first_name": "John",
"last_name": "Apple"
},
{
"id": 2,
"first_name": "Bob",
"last_name": "Banana"
},
{
"id": 3,
"first_name": "Charles",
"last_name": "Carrot"
}
]
}
我想将数据转换为以下形式,并将其作为可观察对象返回
[
{
"first_name": "John",
"last_name": "Apple"
},
{
"first_name": "Bob",
"last_name": "Banana"
},
{
"first_name": "Charles",
"last_name": "Carrot"
}
]
我尝试了以下方法,但它返回未定义。
getStudentsName(): Observable<any> {
const requestUrl = this.rootURL + `students/`;
let studentsInfo = this.http.get<any>(requestUrl).pipe(map(o => o.students));
return studentsInfo.pipe(map(students => {students.first_name, students.last_name}));
}
订阅 observable 时返回 undefined
this.getStudentsInfoService.getStudentsName()
.subscribe((result) => console.log('here', result));
【问题讨论】:
标签: json angular typescript rxjs rxjs-observables