//从数据获取相同数据生成多维数组 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]) } }
标签: 多维数组
上面是“从数据获取相同数据生成多维数组等数组相关j”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_109.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!