【发布时间】:2021-07-09 16:04:19
【问题描述】:
我需要在一个独特的 RxJS 管道中多次处理 http.get 响应。这是 JSON 响应的一部分:
[
{
"id": 1,
"layerName": "Primary",
"hierarchyCount": 2,
"layerHierarchies": [
{
"hierarchyOrder": 1,
"id": 3,
"name": "Secant Piles"
},
{
"hierarchyOrder": 2,
"id": 6,
"name": "As-Designed"
}
],
"gisViewTypeId": "M1",
"coordinateSystemId": 5,
"verticalCoordinateSystemId": 7,
"measurementUnitSymbol": null,
"color": "#fabed4",
"stroke": true,
"weight": 3,
"opacity": 1,
"fill": true,
"fillColor": "#f032e6",
"fillOpacity": 0.2,
"active": false,
"pointTypeId": 2,
"shiftX": 0,
"shiftY": 0
},
...
]
通过以下管道,我得到hierarchyCount 的最大值,如下所示:
this.layerHierarchi$ = this.http.get<LayerHierarchiesEntity[]>(baseURL + "Structure/StructureHierarchy", { params: layerParams, headers: headers })
return this.layerHierarchi$.pipe(
mergeMap((value) => from(value)),
pluck("hierarchyCount"),
max(),
// mergeMap(maxHierarchyCount => this.layerHierarchi$),
)
如您所见,在注释的管道的最后一行中,我尝试获取原始的http.get 响应以继续处理。
我不确定在 mergeMap 运算符中进行另一个调用是否正确,或者是否有另一种技术或 RxJS 运算符来处理这个问题?换句话说,我在整个管道中多次需要原始响应。
【问题讨论】: