-1
我申請基礎上,選擇單選按鈕,過濾器如何使它更有效,而無需使用if條件如何以有效的方式編寫以下代碼?
applyExtraFilter() {
this.moreFilter = !this.moreFilter;
this.allItems = this.listings;
if (this.deliveryConcession[0].checked) {
this.allItems = this.allItems.filter(fil => fil.seatingConcession.parking == this.deliveryConcession[0].checked);
}
if (this.deliveryConcession[1].checked) {
this.allItems = this.allItems.filter(fil => fil.seatingConcession.parking == this.deliveryConcession[2].checked);
}
if (this.deliveryConcession[2].checked) {
this.allItems = this.allItems.filter(fil => fil.seatingConcession.parking == this.deliveryConcession[3].checked);
}
if (this.seatConcession[0].checked) {
this.allItems = this.allItems.filter(fil => fil.seatingConcession.parking == this.seatConcession[0].checked);
}
if (this.seatConcession[1].checked) {
this.allItems = this.allItems.filter(fil => fil.seatingConcession.parking == this.seatConcession[1].checked);
}
if (this.seatConcession[2].checked) {
this.allItems = this.allItems.filter(fil => fil.seatingConcession.parking == this.seatConcession[3].checked);
}
this.setPage(1);
}
你明確訪問'this.deliveryConcession'項而不是迭代它的任何具體原因? –
實際上沒有具體的原因 – user2280016
我有一個解決方案,但我意識到你只是在第一種情況下迭代'[0,2,3]'而在第二種情況下'[0,1,3]' 。 –