2013-11-03 80 views
0

我試圖動態填充表中的列:http://jsfiddle.net/REjUv/1/angularjs動態設置綁定或模型

$範圍具有的每一個屬性名稱和項目爲行數組列定義的數組

我試圖設置TD元素與名稱的項目的屬性的內容在相關列

<div ng-app ng-controller='ListController'> 
    <table> 
     <tr> 
      <th ng-repeat='column in columns'>{{column.text}}</th> 
     </tr> 
     <tr ng-repeat='item in items'> 
      <td ng-repeat='column in columns'> 
       <!--how do i set the ng-bind to item.[column.name]--> 
       <label type='text' ng-bind='item.name' /> 
      </td> 
     </tr> 
    </table> 
</div> 


function ListController($scope){ 
    $scope.columns = [ 
     { name: 'id', text: 'Id' }, 
     { name: 'code', text: 'Code' }, 
     { name: 'name', text: 'Name' } 
    ]; 

    $scope.items = [ 
     { id:1, code: 'A', name: 'AAA' }, 
     { id:2, code: 'B', name: 'BBB' }, 
     { id:3, code: 'C', name: 'CCC' }, 
     { id:4, code: 'D', name: 'DDD' } 
    ]; 
} 

回答

0

這?

<td ng-repeat='column in columns'>{{item[column.name]}</td> 

FIDDLE