2017-07-07 50 views
0
<div ng-controller="reportCtrl"> 
     <table class="table table-hover"> 
      <thead class="row col-md-3"> 
       <tr class="row"> 
        <th class="col-md-6">Key </th> 
        <th class="col-md-6"> Value</th> 
       </tr> 
      </thead> 
      <tbody ng-repeat="param in params" class="row col-md-3"> 
       <tr class="row"> 
        <td class="col-md-6 info">{{param.key}}</td> 
        <td class="col-md-6 info">{{param.val}}</td> 
       </tr> 
      </tbody> 
     </table> 
</div> 

我有這樣的表,當我使用的是NG-重複的結果是很奇怪的引導電網系統.. my Table舉表不NG-重複工作良好

我試着與電網系統播放,但dosent似乎是它可以幫助..

+0

試試你的代碼,而無需使用引導類。我認爲問題可能是'class =「row col-md-3」' –

回答

3

不需要row col-md-3類添加到table-bodyrow類的tr元素。此外,如果您要重複項目,則ng-repeat需要位於tr元素上,如果元素位於tbody元素上,那麼您將有多個不必要的tbody元素。

請參閱工作example

如果你只是想要一個簡單的表:

<div ng-controller="TestController as vm"> 
    <table class="table table-bordered table-striped table-hover"> 
    <thead> 
     <tr> 
     <th>Key </th> 
     <th> Value</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr ng-repeat="item in vm.items"> 
     <td>{{$index}}</td> 
     <td>{{item}}</td> 
     </tr> 
    </tbody> 
    </table> 
</div> 

JS:

var myApp = angular.module('myApp',[]) 
.controller('TestController', ['$scope', function($scope) { 
    var self = this; 

    self.items = ['one', 'two', 'three', 'four']; 
}]) 

如果您不需要table element可以使用引導rowcol-*

<div class="row"> 
    <div class="col-sm-6"> 
     <h1>Key</h1> 
    </div> 
    <div class="col-sm-6"> 
     <h1>Value</h1> 
    </div> 
    </div> 
    <div class="row" ng-repeat="item in vm.items"> 
    <div class="col-sm-6"> 
     {{$index}} 
    </div> 
    <div class="col-sm-6"> 
     {{item}} 
    </div> 
    </div> 
0

嘗試刪除類=「行。」

<div ng-controller="reportCtrl"> 
     <table class="table table-hover"> 
      <thead> 
       <tr> 
        <th>Key </th> 
        <th> Value</th> 
       </tr> 
      </thead> 
      <tbody ng-repeat="param in params"> 
       <tr> 
        <td>{{param.key}}</td> 
        <td>{{param.val}}</td> 
       </tr> 
      </tbody> 
     </table> 
</div> 
+0

但隨後表格以全角出現,我希望它是小表格 –

+0

一個簡單的破解就是將整個表格封裝在網格中。 '

' –

0
Remove the bootstrap classes row, col-md-6 in tbody ,use the below code.. 
for all medias, it will be resized 

<div ng-controller="reportCtrl" class="table-responsive> 
    <table class="table table-hover table-bordered"> 
     <thead> 
      <tr> 
       <th>Key </th> 
       <th> Value</th> 
      </tr> 
     </thead> 
     <tbody ng-repeat="param in params"> 
      <tr> 
       <td>{{param.key}}</td> 
       <td>{{param.val}}</td> 
      </tr> 
     </tbody> 
    </table> 
</div> 
0
<div ng-controller="reportCtrl"> 
    <table class="table table-hover"> 
    <div class="row col-md-3"> 
     <thead class="row"> 
      <tr> 
       <th class="col-md-6">Key </th> 
       <th class="col-md-6"> Value</th> 
      </tr> 
     </thead> 
     <tbody ng-repeat="param in params"> 
      <tr class="row"> 
       <td class="col-md-6 info">{{param.key}}</td> 
       <td class="col-md-6 info">{{param.val}}</td> 
      </tr> 
     </tbody> 
    </div> 
    </table> 

我已經作出一些改變,像覆蓋整個表分爲3個部門,然後
將他們進一步陷入6-6的部份和TDS。只要看看它是否有效。

0

你可以試試這個代碼 通過消除col-md-3 和樣式表與width:auto

<div ng-controller="reportCtrl"> 
    <table class="table table-hover" style="width:auto"> 
    <thead class="row "> 
     <tr class="row"> 
     <th class="col-md-6">Key </th> 
     <th class="col-md-6"> Value</th> 
     </tr> 
    </thead> 
    <tbody ng-repeat="param in params" class="row "> 
     <tr class="row"> 
     <td class="col-md-6 info">{{param.key}}</td> 
     <td class="col-md-6 info">{{param.val}}</td> 
     </tr> 
    </tbody> 
    <tbody ng-repeat="param in params" class="row "> 
     <tr class="row"> 
     <td class="col-md-6 info">{{param.key}}</td> 
     <td class="col-md-6 info">{{param.val}}</td> 
     </tr> 
    </tbody> 
    </table> 
</div>