AngularJS:从二维数组显示table
AngularJS: Display table from 2D Array
我试图找到一种方法来显示二维数组中的 table。目前我无法显示任何内容,需要一个简单的 bool 1/0。任何建议将不胜感激。
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>
从 xxx[0]
中删除 [0]
:
ng-repeat="yyy in xxx track by $index"
这假设 Matrix
在 $scope.Matrix
只需一个 track by $index
(以便 angular
可以跟踪它),你就完成了:-
*.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]
];
我试图找到一种方法来显示二维数组中的 table。目前我无法显示任何内容,需要一个简单的 bool 1/0。任何建议将不胜感激。
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>
从 xxx[0]
中删除 [0]
:
ng-repeat="yyy in xxx track by $index"
这假设 Matrix
在 $scope.Matrix
只需一个 track by $index
(以便 angular
可以跟踪它),你就完成了:-
*.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,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