jsは配列オブジェクトのマルチ削除を実現します.
7397 ワード
jsは配列オブジェクトのマルチ削除を実現します.
delete = () => {
const Ids = this.state.selectRows.map(item => {
return item.Id;
});// id
if (Ids.length === 1) {
//
const Id = this.state.selectRows[0].Id;
//
let indexdel = this.state.data.findIndex(item => item.Id === Id);
this.state.data.splice(indexdel, 1);
let data = this.state.data;
this.setState({
data,
selectRows: []
});
} else {
//
let alldata = this.state.data;
for (let i= alldata.length - 1; i>= 0; i--) {
//
let id = alldata[i].Id;
for (let j = Ids.length; j >= 0; j--) {
// id id
if (id=== Ids[j]) {
// id
alldata.splice(index, 1);//
}
}
}
let data = alldata;
this.setState({
data,
selectRows: []
});
}
};