这是较旧的实现,我想获得 HeatingDesired 值
//1st api call
this.siteService.getScheduleParamsByRoomRef('temp and air and desired and heating', this.refs.roomRef).subscribe(({ rows }) => {
if (rows.length > 0) {
rows.forEach((row) => {
let pointId = this.helperService.stripHaystackTypeMapping(row['id']).split(' ')[0];
//2nd api call
this.siteService.getHisPointData(pointId, 'current').subscribe(({ rows, meta }) => {
let metaVal = meta;
if (rows.length > 0) {
let HeatingDesired = this.helperService.stripHaystackTypeMapping(rows[0].val);
}
});
});
}
});
==================================================== =========================
现在我正在尝试使用 switchmap 并订阅最终响应
getDesiredHeatingTemp(eleId){
//1st api call
return this.siteService.getScheduleParamsByRoomRef('temp and air and desired and heating', eleId).pipe(
switchMap((a)=>{
a.forEach((m) => {
let pointId = this.helperService.stripHaystackTypeMapping(m['id']).split(' ')[0];
//2nd api call
return this.siteService.getHisPointData(pointId, 'current')
})
}))
}
this.getDesiredHeatingTemp(eleId).subscribe((a) => console.log(a))
But is gives me error saying
Argument of type '(a: any) => void' is not assignable to parameter of type '(value: any, index: number) => ObservableInput<any>'.
Type 'void' is not assignable to type 'ObservableInput<any>'.
第二个 api 调用需要我从第一个 api 调用中获得的参数
更新
The response which I get from 1st api call looks like
a=
cols: (23) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
meta: {ver: "2.0"}
rows: [{…}]
a=
cols: (23) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
meta: {ver: "2.0"}
rows: Array(1)
0:
air: "m:"
desired: "m:"
id: "r:5d90685e647845530d95ad0a nizam346_2-VAV-9600-desiredTempHeating"
kind: "Number"
__proto__: Object
length: 1
__proto__: Array(0)
从第一个 api 调用的上述响应中,我想获取 rows[0].id 并将其传递给第二个 api 调用。
我尝试使用 map, foreach 但在调试时执行并没有进入 const obs = a.forEach((m)=>{ let pointId = this.helperService.stripHaystackTypeMapping(m.rows[0]['id']) .split(' ')[0];
getDesiredHeatingTemp(eleId){
return this.siteService.getScheduleParamsByRoomRef('temp and air and desired and heating', eleId)
.pipe(
switchMap(a => {
const obs = a.forEach((m)=>{
let pointId = this.helperService.stripHaystackTypeMapping(m.rows[0]['id']).split(' ')[0];
return this.siteService.getHisPointData(pointId, 'current')
})
return forkJoin(obs)
}))
}