0
해당 개체의 ID가 비교할 개체의 ID와 같을 때 배열의 개체를 삭제하고 싶습니다. 현재, 단지각도 2 : 배열의 개체 삭제
if(this.selectedProducts.length > 0){
for(let x of this.selectedProducts){
if(prod._id === x._id){
this.selectedProducts.splice(x,1); //this is the part where I 'delete' the object
this.appended = false;
}else{
this.appended = true;
}
}
if (this.appended) {
this.selectedProducts.push(prod);
}
}else{
this.selectedProducts.push(prod);
}
this.selectEvent.emit(this.selectedProducts);
}
당신의 ID가 하나 somehting로 제공 될 수있다. 각도와 관련된 것을 보지 못했습니다. –
@AniruddhaDas – Char
이벤트 발생기가 각을 이루고 있습니다.'selectedProducts'가 전체 조작이 가능할 수있는 사전 인 경우 selectedProducts [prod._id] = prod' – Pace