从数据获取相同数据生成多维数组等数组相关j

2024年06月24日 建站教程

//从数据获取相同数据生成多维数组
      let tableList = {},
        tableNewsList = [];
      for (let i = 0; i < this.list.length; i++) {
        let tableListArr = this.list[i];
        if (!tableList[tableListArr.hospital_name]) {
          tableNewsList.push({
            Id: tableListArr.Id,
            hospital_name: tableListArr.hospital_name,
            data: [tableListArr]
          });
          tableList[tableListArr.hospital_name] = tableListArr;
        } else {
          for (let j = 0; j < tableNewsList.length; j++) {
            let tableListArr2 = tableNewsList[j];
            if (tableListArr2.hospital_name == tableListArr.hospital_name) {
              tableListArr2.data.push(tableListArr);
              break;
            }
          }
        }
      }
      //获取合计,生成数组
      let listCount = 0
      let listCountArr = []
      for (let k = 0; k < tableNewsList.length; k++) {
        for (let l = 0; l < tableNewsList[k].data.length; l++) {
          listCount += parseInt(tableNewsList[k].data[l].info_cnt)
        }
        listCountArr.push(listCount)
      }

      //自定义合计数组
      const listCountArr2 = []
      listCountArr.forEach(function (item) {
        listCountArr2.push({
          Id: item,
          data: {
            Id: item,
            hospital_name: '合计',
            info_cnt: item
          }
        })
      });
      //自定义列表数组和合计数组
      var length = Math.min(tableNewsList.length, listCountArr2.length)
      var result1 = []
      var result2 = []
      for (var i = 0; i < length; i++) {
        result1.push(tableNewsList[i].data)
        result2.push(listCountArr2[i].data)
      }
      //合并列表数组和合计数组
      var typesList = []
      var typesList2 = []
      for (let j = 0; j < result1.length; j++) {
        typesList = result1[j].concat(result2[j]);
        typesList2.push(typesList)

      }
      //获取数组赋值
      var newsListArr = []
      for (let k = 0; k < typesList2.length; k++) {
        for (let l = 0; l < typesList2[k].length; l++) {
          newsListArr.push(typesList2[k][l])
        }
      }

本文链接:http://so.lmcjl.com/news/7167/

展开阅读全文
相关内容