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は、1つまたはsomehtingとして来るかもしれません。 –
@AniruddhaDas – Char
のイベントエミッタが角張っています。 'selectedProducts'は、全体の操作がちょうど' selectedproducts [prod._id] = prod'となる辞書だった場合 – Pace