管道内的映射将被忽略,并且不会触发 http 调用
map inside pipe is ignored and http call is not triggered
我在调用网络服务时遇到问题
我在这里创建了效果
$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);
}
终于Success
行动
export class GetDirectionsSuccess implements Action {
public readonly type = ESchedulesActions.GetSchedulesByDirectionSuccess;
constructor(public payload: ISchedules) {}
}
减速器
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);
}
我在调用网络服务时遇到问题
我在这里创建了效果
$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);
}
终于Success
行动
export class GetDirectionsSuccess implements Action {
public readonly type = ESchedulesActions.GetSchedulesByDirectionSuccess;
constructor(public payload: ISchedules) {}
}
减速器
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);
}