I have select many data and post to back end, it is succeed but after that i want to delete array data in front end without reload. I try with splice it is only delete one or two max is tow
Here is my code
JavaScript
x
7
1
const itemOrder = this.baskets.filter((el)=>{
2
return el.checkbox == true
3
});
4
5
HTTP().post('/order',itemOrder).then(()=>{
6
});
7
after then i wont to delete all this baskets if checkbox is true
i have try
JavaScript
1
7
1
for(let i in this.baskets) {
2
if(this.baskets[i].checkbox == true) {
3
console.log(i);
4
this.baskets.splice(i,1);
5
}
6
}
7
and also try this
JavaScript
1
2
1
this.baskets.splice(this.baskets.findIndex(e => e.checkbox == true),1);
2
still does not work as my expectation
Advertisement
Answer
You can filter all false checkboxes:
JavaScript
1
11
11
1
let baskets = [
2
{id: 1, checkbox: true},
3
{id: 2, checkbox: true},
4
{id: 3, checkbox: false},
5
{id: 4, checkbox: true},
6
{id: 5, checkbox: true}
7
]
8
9
baskets = baskets.filter(b => b.checkbox === false)
10
11
console.log(baskets)