我选择了很多数据并发布到后端,它是成功的,但在那之后我想删除前端的数组数据而不重新加载。我尝试用 splice 它只是删除一两个 max is tow
这是我的代码
const itemOrder = this.baskets.filter((el)=>{
return el.checkbox == true
});
HTTP().post('/order',itemOrder).then(()=>{
});
然后如果复选框为真,我将不会删除所有这些篮子
我试过了
for(let i in this.baskets) {
if(this.baskets[i].checkbox == true) {
console.log(i);
this.baskets.splice(i,1);
}
}
也试试这个
this.baskets.splice(this.baskets.findIndex(e => e.checkbox == true),1);
还是没有达到我的预期
最佳答案
您可以过滤所有错误的复选框:
let baskets = [
{id: 1, checkbox: true},
{id: 2, checkbox: true},
{id: 3, checkbox: false},
{id: 4, checkbox: true},
{id: 5, checkbox: true}
]
baskets = baskets.filter(b => b.checkbox === false)
console.log(baskets)
关于javascript - 如果条件vue js,如何删除数组中的许多数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68807133/