0
我從列表中選擇了多個ion-items,但我想從數組中刪除多個相同的項目。如何在Angular 2中刪除數組中的多個值
HTML代碼
<div class="ion-item optionalItem">
<button class="ion-button" ion-item *ngFor="let configop of interiorOption" (click)="itemSelected(configop)">
<span class="color-name">{{ configop.intName }}</span>
<span class="color-price">{{ configop.price }}</span>
</button>
</div>
打字稿代碼
this.Array.push(configop);
for (let key in this.Array) {
this.Array2.push(this.Array[key])
}
for(let i = 0; i < this.Array.length; i++) {
if(this.Array[i] === this.Array2[i])
{
this.Array.pop();
}
console.log("Sorted",this.Array);
}
請更具體的問題是什麼,你想得到什麼樣的結果 –
我不想在我的數組中有多個相同的值。 如果用戶按下「內部」按鈕兩次或多次。數組應該存儲「內部」一次。不是多次。 我想彈出數組中的所有多個值。 @Bo Chen –
爲什麼不只是檢查數組是否存在,如果存在則拋出錯誤在用戶說:「這個項目已被添加,請使用一個新的名稱..」或類似的東西。 – DDelgro