arr.some()与arr.every();
// tabledata第一层只要有在selection里面就是全选
const isSelect = selection.some((el) => {
const tableDataIds = this.tableData.map((j) => j.spuCode);
return tableDataIds.includes(el.spuCode);
});
// tableDate第一层只要有不在selection里面就是全不选
const isCancel = !this.tableData.every((el) => {
const selectIds = selection.map((j) => j.spuCode);
return selectIds.includes(el.spuCode);
});
if (isSelect) {
selection.map((el) => {
if (el.children) {
// 解决子组件没有被勾选到
this.setChildren(el.children, true);
}
});
}
if (isCancel) {
this.tableData.map((el) => {
if (el.children) {
// 解决子组件没有被勾选到
this.setChildren(el.children, false);
}
});
}
其他循环更多用法见: