let firstIndex = null;
let secondIndex = null;
const findItemNested = (arr, itemId, nestingKey) =>
arr.reduce((a, item, myIndex) => {
if (a) return a;
if (item.id === itemId) {
secondIndex = myIndex;
return myIndex;
}
if (item[nestingKey]) {
firstIndex = myIndex;
return findItemNested(item[nestingKey], itemId, nestingKey);
}
}, null);
findItemNested(this.editData.detailList, id, "detailList");
// 减去父级批次出库数量
this.editData.detailList[firstIndex].outBatchQuantity -=
this.editData.detailList[firstIndex].detailList[
secondIndex
].outQuantity;
// 删除
this.editData.detailList[firstIndex].detailList.splice(secondIndex, 1);
自己记录下 找到多层detailList里面的某一id进行删除