gpt4 book ai didi

javascript - 管道内的映射被忽略并且不会触发http调用

转载 作者:行者123 更新时间:2023-12-01 00:21:05 24 4
gpt4 key购买 nike

我在调用效果上的 Web 服务时遇到问题

我在这里创建了效果

$LoadSchedulingsByMission = createEffect(() =>
this.actions$.pipe(
ofType<any>(ESchedulesActions.GetSchedulesByDirection),
mergeMap(action =>
this.apiCallsService.getDirections(action.payload, '2016-04-18').pipe(
map(trips => ({ type: ESchedulesActions.GetSchedulesByDirectionSuccess, payload: trips })),
catchError(() => EMPTY)
)
)
)
);

采用字符串数组的 GetSchedulesByDirection 操作

export class GetDirections implements Action {
public readonly type = ESchedulesActions.GetSchedulesByDirection;
constructor(public payload: string[]) {}
}

然后我调用一个 http 服务,该服务采用上面的字符串数组。

getDirections(dataArrayToLoop: string[], date:string) {
const groupByDirection:any={};
dataArrayToLoop.map(elm=> {
let dirUrl=`.....date=${date}&directions=${elm}`
this.http.get<ISchedules>(dirUrl).pipe(map(dirData=>{
groupByDirection[elm].push(dirData.data)
}))
})
return of(groupByDirection);
}

最后成功操作

export class GetDirectionsSuccess implements Action {
public readonly type = ESchedulesActions.GetSchedulesByDirectionSuccess;
constructor(public payload: ISchedules) {}
}

reducer

case ESchedulesActions.GetSchedulesByDirection: {
return {
...state,
};
}
case ESchedulesActions.GetSchedulesByDirectionSuccess: {
return {
...state,
directions: action.payload
};
}

问题是没有触发http调用,我验证了dataarray不为空

最佳答案

您将在回调发生之前返回 of(groupByDirection)。你需要这样的东西:

getDirections(dataArrayToLoop: string[], date:string) {
const groupByDirection = dataArrayToLoop.map(elm => {
let dirUrl=`.....date=${date}&directions=${elm}`;

return this.http.get<ISchedules>(dirUrl).pipe(
map(dirData=> dirData.data),
);
})
return combineLatest(groupByDirection);
}

关于javascript - 管道内的映射被忽略并且不会触发http调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59424457/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com