以下是一个实现上述要求的changeColumn方法的示例代码:

function changeColumn(arr) {
  // 遍历tableConfig,将所有的hide属性设置为false
  tableConfig.forEach((column) => {
    column.hide = false;
  });

  // 第二次遍历,将id为1,2,3的hide属性设置为true
  tableConfig.forEach((column) => {
    if (column.id >= 1 && column.id <= 3) {
      column.hide = true;
    }
  });

  // 第三次遍历,根据arr数组的值设置对应id的hide属性为true
  arr.forEach((value) => {
    if (value === '1') {
      // arr数组中包含1,将id为4-7的hide属性设置为true
      tableConfig.forEach((column) => {
        if (column.id >= 4 && column.id <= 7) {
          column.hide = true;
        }
      });
    } else if (value === '2') {
      // arr数组中包含2,将id为8-10的hide属性设置为true
      tableConfig.forEach((column) => {
        if (column.id >= 8 && column.id <= 10) {
          column.hide = true;
        }
      });
    } else if (value === '3') {
      // arr数组中包含3,将id为11-16的hide属性设置为true
      tableConfig.forEach((column) => {
        if (column.id >= 11 && column.id <= 16) {
          column.hide = true;
        }
      });
    } else if (value === '4') {
      // arr数组中包含4,将id为17-24的hide属性设置为true
      tableConfig.forEach((column) => {
        if (column.id >= 17 && column.id <= 24) {
          column.hide = true;
        }
      });
    }
  });
}

请注意,上述代码中的tableConfig是一个包含列配置的数组,每个列配置对象都有一个id属性和一个hide属性。changeColumn方法接收一个arr参数,该参数是一个包含字符串的数组。根据arr的值,将tableConfig中对应id的列的hide属性设置为true。


原文地址: https://www.cveoy.top/t/topic/i6JP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录