处理数据

1.vue:element-ul

2.select的分组组件,默认value = ['a', 'b', 'c'];

3.后台希望是value = [{groud_a: ['a', 'b']}, { group_b:['c'] } ]

so................

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <table border="1" collp>
      <tr>
        <th></th>
        <th>平台</th>
        <th>软件</th>
        <th>版本</th>
      </tr>
      <tr>
        <td rowspan="5">组2</td>
        <td rowspan="2">平台2</td>
        <td>软件2</td>
        <td>版本2</td>
      </tr>
      <tr>
        <!-- <td>组22</td> -->
        <!-- <td >平台22</td> -->
        <td>软件22</td>
        <td>版本22</td>
      </tr>
      <!-- /////////////////////////////////////////////////////////////// -->
      <tr>
        <!-- <td>组22</td> -->
        <td rowspan="3">平台22</td>
        <td>软件22</td>
        <td>版本22</td>
      </tr>
       <tr>
        <!-- <td>组23</td>
        <td>平台23</td> -->
        <td>软件23</td>
        <td>版本23</td>
      </tr>
      <tr>
        <!-- <td>组23</td>
        <td>平台23</td> -->
        <td>软件23</td>
        <td>版本23</td>
      </tr>
    </table>
    <script>
      var value7 = ['b1', 'h5', 's3'];
      var resultData = {} ;
      var data = [
        {
          name: 'group_b',
          group: ['b1', 'b2', 'b3', 'b5']
        },
        {
          name: 'group_c',
          group: ['c1', 'c2', 'c3', 'c5']
        },
        {
          name: 'group_h',
          group: ['h1', 'h2', 'h3', 'h5']
        },
        {
          name: 'group_v',
          group: ['v1', 'v2', 'v3', 'v5']
        },
        {
          name: 'group_s',
          group: ['s1', 's2', 's3', 's5']
        }
      ];
      var allGroup = [];

//所有组
      for(var n=0; n<data.length; n++) {
        allGroup.push({
          [data[n].name] : []
        })
      }
      console.log(allGroup)
//过滤
      for(var i=0; i<data.length; i++) {
        var d = data[i]
        var index = i
        for(var j=0; j<value7.length; j++) {
          if(d.group.includes(value7[j])) {
            allGroup[index][d.name].push(value7[j])
          }
        }
      }
//清除空数据
      var data2 = data
      for(var u=0; u<data2.length; u++) {
        // console.log(allGroup[u])
        let len = allGroup[u][data2[u].name].length
        console.log(allGroup[u][data2[u].name].length)
        if(len == 0) {
          allGroup.splice(u,1)
          data2.splice(u,1)
          u--
        }
      }
      console.log(allGroup)


    </script>
</body>
</html>

 

posted @ 2018-06-08 22:58  巫瞅瞅  阅读(122)  评论(0编辑  收藏  举报