由于我正在进行服务器端滚动,因此我对如何附加新数据有疑问。当新数据到达时,帖子正在删除旧数据但我只想追加新数据而不是删除帖子中的旧数据
TS
page = 1;
constructor(private store: Store) {
this.store.dispatch(new GetPostsPerPage('', this.page.toString()));
}
onScroll() {
this.store.dispatch(new GetPostsPerPage('', (this.page += 1).toString()));
}
状态
@Action(GetPostsPerPage)
getPostsPerPage(ctx: StateContext<PostStateModel>, { key, pageNumber }: GetPostsPerPage) {
return this.postsService.getPostsPerPage(key, pageNumber).pipe(
tap((result: Post[]) => {
console.log(result);
ctx.patchState({
posts: result['data'],
});
}),
catchError(err => {
console.log(err);
return throwError(err);
})
);
}