代码之家  ›  专栏  ›  技术社区  ›  Varun Sharma

用html和javascript实现自定义表的头?

  •  0
  • Varun Sharma  · 技术社区  · 6 年前

    我正在基于json数据实现表。所以现在我可以打印表,但不能实现列标题。

    http://jsfiddle.net/varunPes/0n9fmawb/74/

    var data = {
    "managment":
        {
                "Notice":{
                "Red color" :{"delete":true,"enable":true,"view":true} ,
                "Yellow color":{"delete":true,"enable":true,"view":true},
                "Specail color":{"delete":true,"enable":true,"view":true},
                },
                "Black Notice":{"delete":true,"enable":true,"view":true},
        },
    "Faculty":
        {
            "salary":{"delete":true,"enable":true,"view":true},
           
        },
    };
    
    var zoneHtml = '';
    
    
         
          for (var zoneKey in data) {
            zoneHtml += '<div class="zone" style="border-bottom:1px solid #696768">';
            zoneHtml += ('<div class="row"><div class="col-sm-3" style="font-size:21px;">' + zoneKey + '</div><div class="col-sm-6">PORTAL</div></div>');
            var jsonData = data[zoneKey];
            for (var listUI in jsonData) {
              zoneHtml += '<div class="jsonData">';
              zoneHtml += ('<h2>' + listUI + '</h2>');
              var ports = jsonData[listUI];
              zoneHtml += '<ul class="port">';
              for (var port in ports) {
                if (typeof ports[port] === 'object') {
               
                  zoneHtml += '<div class="row">'
                  zoneHtml += '<div class="col-sm-12">' + port + ':';
                  for (var i in ports[port]) {
                    zoneHtml += '<li class="checkBoxProp"><input type="checkbox" id="' + i + '" ' + (ports[port][i] ? " checked " : "") + '      ></li>';
    
                  }
                  zoneHtml += '</div></div>';
                } else {
                  zoneHtml += '<li class="checkBoxProp"><input type="checkbox" id="' + i + '" ' + (ports[port] ? " checked " : "") + '      ></li>';
                }
    
              }
              zoneHtml += '</ul>';
            
              zoneHtml += '</div>';
            }
            zoneHtml += ('</div>');
          }
    
          $("#zone").html(zoneHtml);
      .jsonData{
        margin-left:5%;
      }
      li
    { 
    display:inline; 
    }  
    .checkBoxProp{
      margin-left:4%;
      font-size:20px;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <div id="zone"></div>

    expacted输出应如下屏幕截图: enter image description here

    0 回复  |  直到 6 年前