多个动作的效果 angular
Effects with multiple actions angular
我正在尝试创建一个从商店 (this.libraryReferencesStoreFacade.selectSelectedRows$)
循环收集信息的效果,最后多次调用另一个操作 (LibraryReferencesActions.patch({pathParameters: { id: 120},request: { id: row.id, group: 26 }})
。
我尝试了以下代码但没有成功,请帮助我?
@Effect()
someEffect$: Observable<Action> = this.actions$.pipe(
ofType(LibraryReferencesActions.createGroupSuccess),
withLatestFrom(this.libraryReferencesStoreFacade.selectSelectedRows$),
switchMap(([, rows]) => {
console.log(rows,"")
let Observables: Array<Observable<any>> = [];
rows.forEach((row) => {
Observables.push(
LibraryReferencesActions.patch({
pathParameters: { id: 120 },
request: { id: row.id, group: 26 },
})
);
});
const observables: Array<Observable<any>> = Observables;
return forkJoin(observables).map(result => new
LibraryReferencesActions.refreshList())
}
})
)
也尝试过:
addGroupToLib$ = createEffect(() => {
return this.actions$.pipe(
ofType(LibraryReferencesActions.createGroupSuccess),
withLatestFrom(this.libraryReferencesStoreFacade.selectSelectedRows$),
map(([, rows]) => {
let Observables: any = [];
rows.forEach((row) => {
Observables.push(
LibraryReferencesActions.patch({
pathParameters: { id: 120 },
request: { id: 120, group: 26 },
})
);
});
forkJoin(Observables).pipe(
map(() => {
return LibraryReferencesActions.refreshList();
})
);
})
);
});
我认为您可以将 refreshList
操作添加到 patch
操作数组的末尾,它们应该 运行 按顺序排列:
addGroupToLib$ = createEffect(() => {
return this.actions$.pipe(
ofType(LibraryReferencesActions.createGroupSuccess),
withLatestFrom(this.libraryReferencesStoreFacade.selectSelectedRows$),
switchMap(([, rows]) => {
return rows
.map(row => {
return LibraryReferencesActions.patch({
pathParameters: { id: 120 },
request: { id: row.id, group: 26 }
})
})
.concat(
LibraryReferencesActions.refreshList()
)
})
);
});
我正在尝试创建一个从商店 (this.libraryReferencesStoreFacade.selectSelectedRows$)
循环收集信息的效果,最后多次调用另一个操作 (LibraryReferencesActions.patch({pathParameters: { id: 120},request: { id: row.id, group: 26 }})
。
我尝试了以下代码但没有成功,请帮助我?
@Effect()
someEffect$: Observable<Action> = this.actions$.pipe(
ofType(LibraryReferencesActions.createGroupSuccess),
withLatestFrom(this.libraryReferencesStoreFacade.selectSelectedRows$),
switchMap(([, rows]) => {
console.log(rows,"")
let Observables: Array<Observable<any>> = [];
rows.forEach((row) => {
Observables.push(
LibraryReferencesActions.patch({
pathParameters: { id: 120 },
request: { id: row.id, group: 26 },
})
);
});
const observables: Array<Observable<any>> = Observables;
return forkJoin(observables).map(result => new
LibraryReferencesActions.refreshList())
}
})
)
也尝试过:
addGroupToLib$ = createEffect(() => {
return this.actions$.pipe(
ofType(LibraryReferencesActions.createGroupSuccess),
withLatestFrom(this.libraryReferencesStoreFacade.selectSelectedRows$),
map(([, rows]) => {
let Observables: any = [];
rows.forEach((row) => {
Observables.push(
LibraryReferencesActions.patch({
pathParameters: { id: 120 },
request: { id: 120, group: 26 },
})
);
});
forkJoin(Observables).pipe(
map(() => {
return LibraryReferencesActions.refreshList();
})
);
})
);
});
我认为您可以将 refreshList
操作添加到 patch
操作数组的末尾,它们应该 运行 按顺序排列:
addGroupToLib$ = createEffect(() => {
return this.actions$.pipe(
ofType(LibraryReferencesActions.createGroupSuccess),
withLatestFrom(this.libraryReferencesStoreFacade.selectSelectedRows$),
switchMap(([, rows]) => {
return rows
.map(row => {
return LibraryReferencesActions.patch({
pathParameters: { id: 120 },
request: { id: row.id, group: 26 }
})
})
.concat(
LibraryReferencesActions.refreshList()
)
})
);
});