纯原生:

                var myarr = new Array(); //先声明一维
                var m = 0
                for ( var i = 0; i < Math.ceil(device.row.length / 6); i++) { //一维长度为2
                    myarr[i] = new Array(); //再声明二维
                    if(device.row.length<6){
                        for(var j = 0; j<device.row.length;j++){
                            myarr[i][j] = device.row[j+i]
                        }
                    }else{
                        for ( var l = 0; l < 6; l++) { //二维长度为3
                        myarr[i][l] =device.row[m] // 赋值,每个数组元素的值为i+j
                        if(m<device.row.length-1){
                            m++
                        }else{
                            l=7
                        }
                        }
                    }
                }
如果用vue渲染,直接拿myarr数组到tr标签渲染
     <table class="work_table">
                    <tr v-for="(itemOne,index) in myarr" :key="index">
                      <td v-for="(item,index) in itemOne" >
                        <div class="work">
                          <div class="work_suffer">
                            <div class="work_name">
                              <span class="work_engineer">{{item.industry_job_name}}</span>
                              <span class="work_pay">{{item.pay_min}}-{{item.pay_max}}K</span>
                            </div>
                            <p>{{item.city}}    |  {{item.years_of_work_demand}}  |  {{item.education_demand}}</p>
                          </div>
                          <div class="work_staff" >
                            <img :src="item.whole_company_logo" alt="" style="vertical-align: middle">
                            <span style="vertical-align: middle">{{item.company_name}}</span>
                          </div>
                        </div>
                      </td>
                    </tr>
                  </table>
如果是原生就用下面这动态渲染
            for(let y in myarr){
                    tr += "<tr>"
                    for(var r in myarr[y]){
                        if(myarr[y][r].online_status == 1){
                            img_status = 'shebei1.png'
                            tr += "<td><img src="+img_status+"><p>名称"+myarr[y][r].name+"</p><p>IP"+myarr[y][r].ip+"</p></td>"
                        }else if(myarr[y][r].online_status == 0){
                            img_status = 'shebei2.png'
                            tr += "<td style='color:red'><img src="+img_status+"><p>名称"+myarr[y][r].name+"</p><p>IP"+myarr[y][r].ip+"</p></td>";
                        }
                    }
                    tr += "</tr>";
                }
    $('#dev_asset').append(tr)
posted on 2021-01-19 16:03  追星程序媛  阅读(86)  评论(0编辑  收藏  举报