是否可以有多个 pluck 运算符(rxjs)
Is it possible to have multiple pluck operator (rxjs)
我的 HTTP 响应有问题。我只是得到这样的回应:
{
objectArrayList1 : [{...}, {...}, {...}],
objectArrayList2 : [{...}, {...}, {...}],
.
.
.
}
我可以分别做 pluck('objectArrayList1') 和 pluck('objectArrayList2') 。但是是否可以同时对 objectArrayList1 和 objectArrayList2 应用 pluck 运算符(或多个运算符)?例如在管道中;
.pipe(
pluck('objectArrayList1'),
*I would like to work with objectArrayList2 also*
)
定稿
试图得到这样的东西:
this.http.get<responseType>('https://myUrl/somethingtoask', {
params:{
x: '123',
y: '234',
...
}
}).pipe(
pluck('objectArrayList1'),
*I would like to work with objectArrayList2 also*
)
如何分别到达 objectArrayList1 和 objectArrayList2(最好在同一管道中)?
pluck
operator is used only to get one of the object properties. Instead you could use the map
operator with object destructuring 到 return 多个属性。
this.http.get<responseType>('https://myUrl/somethingtoask', {
params:{
x: '123',
y: '234',
...
}
}).pipe(
map(({ objectArrayList1, objectArrayList2 }) => ({ objectArrayList1, objectArrayList2 }))
).subscribe({
next: (response: any) => {
// use `response.objectArrayList1` and `response.objectArrayList2`
},
error: (error: any) => { }
});
我的 HTTP 响应有问题。我只是得到这样的回应:
{
objectArrayList1 : [{...}, {...}, {...}],
objectArrayList2 : [{...}, {...}, {...}],
.
.
.
}
我可以分别做 pluck('objectArrayList1') 和 pluck('objectArrayList2') 。但是是否可以同时对 objectArrayList1 和 objectArrayList2 应用 pluck 运算符(或多个运算符)?例如在管道中;
.pipe(
pluck('objectArrayList1'),
*I would like to work with objectArrayList2 also*
)
定稿
试图得到这样的东西:
this.http.get<responseType>('https://myUrl/somethingtoask', {
params:{
x: '123',
y: '234',
...
}
}).pipe(
pluck('objectArrayList1'),
*I would like to work with objectArrayList2 also*
)
如何分别到达 objectArrayList1 和 objectArrayList2(最好在同一管道中)?
pluck
operator is used only to get one of the object properties. Instead you could use the map
operator with object destructuring 到 return 多个属性。
this.http.get<responseType>('https://myUrl/somethingtoask', {
params:{
x: '123',
y: '234',
...
}
}).pipe(
map(({ objectArrayList1, objectArrayList2 }) => ({ objectArrayList1, objectArrayList2 }))
).subscribe({
next: (response: any) => {
// use `response.objectArrayList1` and `response.objectArrayList2`
},
error: (error: any) => { }
});