zoukankan      html  css  js  c++  java
  • js实现把多个数据分成3个一组

    主要代码:

    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);
                    }
                }

      得到的数据为三个一组

  • 相关阅读:
    区块链
    区块链
    区块链
    区块链
    区块链 – 介绍
    区块链 教程
    Matplotlib 直方图
    Matplotlib 饼图
    Matplotlib 柱状图
    Matplotlib 多个图形
  • 原文地址:https://www.cnblogs.com/lvxisha/p/11446244.html
Copyright © 2011-2022 走看看