我编写了一个 http 函数,它使用 switch map 从一个 http 请求中获取值并将其用作第二个 http 请求中的参数,但是我如何不仅返回最终的 http 请求,还返回第一个 http 请求的数据?
这是我的功能:
.post<RxObservable<unknown>>(
`${this.nextApiEndpoint}ProgramReview/GetAssessmentQuestionNumber`,
body,
{}
)
.pipe(
switchMap((data) => {
return this.http.post<any>(
`${this.nextApiEndpoint}ProgramReview/GetProgramReviewQuestion`,
{ studentId: args.studentId, questionId: data, programReviewId: args.programReviewId },
{}
);
}),
catchError((err) => {
return err;
})
);
}
我在组件中订阅了它并从最终的http请求中获取返回数据,但我还想将第一个请求的数据传递给组件中的订阅。
它可能有点丑陋,但你必须从第二次调用重新映射事件