我正在使用 ngrx 商店。
在我的状态下,我必须物品
export interface ISchedulesState {
schedulings: ISchedules;
actualTrips: ISchedule[];
}
Run Code Online (Sandbox Code Playgroud)
这是我的接口
export interface ISchedules {
[key: string]: ISchedule[];
}
export interface ISchedule {
dest: number;
data: string
}
Run Code Online (Sandbox Code Playgroud)
在减速器中我更新 actualTrips
export const SchedulingReducers = (
state = initialSchedulingState,
action: SchedulesAction
): ISchedulesState => {
switch (action.type) {
case ESchedulesActions.GetSchedulesByDate: {
return {
...state
};
}
case ESchedulesActions.GetSchedulesByDateSuccess: {
return {
...state,
schedulings: action.payload
};
}
case ESchedulesActions.GetSchedulesByTime: {
let time = action.payload;
state.actualTrips = [...(state.schedulings[time] || [])]; …Run Code Online (Sandbox Code Playgroud)