1,数据格式是二维的
如:o:{id:123,
prams:{name:aaa,age:11}
}
的对象
第一步:先获取返回的数据为indexInfoList,遍历转化为一维数组
that.indexInfoList.forEach(ele => {
1 2 3 4 5 6 7 8 9 10 | if (ele.prams.length >= 1) { ele.prams.map((related, index) => { let aaarr = {}; //要拿出来的数据组成新的对象 let brr = Object.assign({}, ele, aaarr); //和原来的数据对象拼接成一个新的 arr.push(brr); }); } else { arr.push(ele); } }); |
得到新的数组
that.tableData = arr; // 得到拼接后的内容
that.rowspan(); // 重新合并行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | rowspan() { // 每次调用清空数据 this .spanArr = []; this .position = 0; console.log( this .tableData); this .tableData.forEach((item, index) => { if (index === 0) { this .spanArr.push(1); this .position = 0; } else { // recordId 为需要合并查询的项 if ( this .tableData[index].recordId === this .tableData[index - 1].recordId ) { this .spanArr[ this .position] += 1; this .spanArr.push(0); } else { this .spanArr.push(1); this .position = index; } } }); }, //调用elementUI的合并方法 objectSpanMethod({ row, column, rowIndex, columnIndex }) { if (columnIndex <= 9) { const _row = this .spanArr[rowIndex]; const _col = _row > 0 ? 1 : 0; return { rowspan: _row, colspan: _col }; } }, |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库