2016-04-15 4 views
0

Ich habe versucht, eine Möglichkeit zu finden, eine Tabelle aus einem 2D-Array anzuzeigen. Im Moment kann ich nichts zur Anzeige bringen, ein einfacher bool 1/0 ist erwünscht. Jeder Rat würde geschätzt werden.AngularJS: Tabelle aus 2D-Array anzeigen

var Matrix = [ 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
     [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1] 
]; 


      <div id = "MatrixTable2"> 
      <table border="1"> 
       <tbody ng-repeat="xxx in Matrix"> 
        <tr width="50px"> 

         <td width="50px" ng-repeat="yyy in xxx[0]"> bool {{yyy}}</td> 
        </tr> 
       </tbody> 
      </table> 
     </div> 

Antwort

1

nur track by $index (so dass angular Spur davon halten) und Sie werden getan: -

*.html

<table border="1"> 
    <tbody ng-repeat="xxx in Matrix"> 
     <tr width="50px"> 
      <td width="50px" ng-repeat="yyy in xxx track by $index">{{yyy}}</td> 
     </tr> 
    </tbody> 
</table> 

*.js

$scope.Matrix = [ 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1], 
    [0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1] 
]; 
0

Drop the [0] von xxx[0]:

ng-repeat="yyy in xxx track by $index" 

Dies setzt voraus, dass Matrix in $scope.Matrix ist

+0

, die entlang Fehler [ngRepeat: Betrogene] bringt –

+1

ich hinzugefügt, um die 'Spur von index' Klausel $: https://docs.angularjs.org/api/ng/directive/ngWiederholen –