主要代码:
var stuCount = res.data;
resetDataFun(stuCount,5)
/**
* col 表示列
* stuCount 表示数组
*/
function resetDataFun(stuCount,col){ if (stuCount.length>0){ var objList = new Object(); var arr = new Array(); var cow = stuCount.length / col == 0 ? stuCount.length / col : Math.ceil((stuCount.length / col)); console.log('行数',cow); for (var i = 1; i <= cow; i++) { var tempArr = []; var temp; if (col * i > stuCount.length) { temp = stuCount.length; } else { temp = col * i; } for (var j = col * (i - 1); j < temp; j++) { tempArr.push(stuCount[j]); } var newObj = new Object(); newObj.data = tempArr arr.push(newObj); } objList.data = arr; this.resetData = objList; console.log(objList); } }
得到的数据为三个一组