我有一个数组中的项目列表。我可以删除一项,并且只有在重新加载页面后,该项才会从列表中消失。该项目已成功从数据库中删除,但该页面并未立即将其从列表中删除,就像我想的那样。
我没有显示任何错误,所以我可能缺少一些东西。...
这是带来兴趣列表的方法:
private uprofileInterests() {
const query2 = {};
query2['uprofileId.equals'] = this.uprofile.id;
return this.interestService.query(query2).subscribe(
(res: HttpResponse<IInterest[]>) => {
this.interests = res.body;
console.log('CONSOLOG: M:uprofileInterests & O: this.interests : ', this.interests);
},
(res: HttpErrorResponse) => this.onError(res.message)
);
}
这是删除项目的方法:
removeProfileInterest(interestId, uprofileId) {
this.interests.forEach(interest => {
if (interest.id === interestId) {
interest.uprofiles.forEach(uprofile => {
if (uprofile.id === uprofileId) {
interest.uprofiles.splice(interest.uprofiles.indexOf(uprofile), 1);
this.subscribeToSaveResponse3(this.interestService.update(interest));
}
});
}
});
}
subscribeToSaveResponse3方法:
private subscribeToSaveResponse3(result: Observable<HttpResponse<IInterest>>) {
result.subscribe((res: HttpResponse<IInterest>) => this.onSaveSuccess2(), (res: HttpErrorResponse) => this.onSaveError());
}
和onSaveSuccess2方法:
private onSaveSuccess2() {
this.isSaving = false;
}
感谢您的帮助!
答案 0 :(得分:1)
按照Igor在评论中所说的,从列表中删除该项目:
this.interests.splice(interest.uprofiles.indexOf(uprofile),1);