我有一个创建新Selections
的表单,提交后需要将该对象推送到我的数组中,这样您就可以在表中看到结果而无需重新加载。我有一个功能:
ngOnInit(): void {
//this.selections - filtered array
//selections - full
this.communicationService.createOrUpdateSelection$.subscribe((response) => {
this.selections.forEach(selection => {
if (selection.directionId === response.directionId && selection.locationId === response.locationId) {
this.selections.push(response);
} else {
this.selectionService.getAll().subscribe(selections => {
selections.push(response);
})
}
});
});
}
在此功能中,response
是我表单中的一个对象。然后,我检查是否有人用选择的Selection
和location
创建了direction
,如果是,则将response
推送到过滤后的数组(如果否)到整个数组。
因此,当我在表中创建具有相同的Selection
和location
的{{1}}时,它会显示重复项,每次提交后重复项的数量都会增加。但是重新加载后,我只有一个uniq direction
。
非常感谢您的帮助!
如果需要,CommunicationService:
Selection