bootstrap合并表格错乱,for循环顺序踩坑

时间:2025-04-02 17:12:05
// 合并表格:按某一列值相同:合并表格 function mergeCells(data, fieldName, colspan, target, fieldList) {//总数据组,列名,,表格名id,合并项属性名 var sortMap = {}; for (var i = 0; i < ; i++) { for (var prop in data[i]) { var fieldArr = ("."); getCount(data[i], prop, fieldArr, 0, sortMap); } } var index = 0; for (var prop in sortMap) { var count = sortMap[prop]; for (var i = 0; i < ; i++) { $(target).bootstrapTable('mergeCells', { index: index, field: fieldList[i], colspan: colspan, rowspan: count }); } index += count; } } function getCount(data, prop, fieldArr, index, sortMap) { if (index == - 1) { if (prop == fieldArr[index]) { var key = '.'+data[prop];//转换类型让数字按照实际创建顺序排序 if ((key)) { sortMap[key] = sortMap[key] + 1; } else { sortMap[key] = 1; } } return; } if (prop == fieldArr[index]) { var sdata = data[prop]; index = index + 1; getCount(sdata, fieldArr[index], fieldArr, index, sortMap); } }