AngularJS中的二维数组
另一个答案是: - 原始问题: 如何使用ng repeat创建二维数组作为表AngularJS中的二维数组,angularjs,Angularjs,另一个答案是: - 原始问题: 如何使用ng repeat创建二维数组作为表 this.boardArr = [ [1,6,3], [5,2,7], [9,10,11], ] 这不起作用: <table class="game-board" ng-controller="GameBoardController as gameBoard"> <tr ng-repeat="row
this.boardArr = [
[1,6,3],
[5,2,7],
[9,10,11],
]
这不起作用:
<table class="game-board" ng-controller="GameBoardController as gameBoard">
<tr ng-repeat="row in boardArr">
<td ng-repeat="col in row">{{boardArr[row][col]}}</td>
</tr>
</table>
{{boardArr[行][col]}
您必须在视图中创建如下表:
<table class="game-board" ng-controller="GameBoardController as gameBoard">
<tr ng-repeat="row in boardArr">
<td ng-repeat="col in row">{{ col }}</td>
</tr>
</table>
<table>
<tr ng-repeat="row in $ctrl.boardArr">
<td ng-repeat="col in row>{{col}}</td>
</tr>
</table>
{{col}}
因此,
ng repeat
将在boardArr
上迭代,然后您可以像上面那样在不同的单元格中显示值。您不必像这样访问要显示的值:boardArr[row][col]
,因为col
已经包含了boardArr[row][col]
的值,您必须循环行,然后循环它们的列,如下所示:
<table class="game-board" ng-controller="GameBoardController as gameBoard">
<tr ng-repeat="row in boardArr">
<td ng-repeat="col in row">{{ col }}</td>
</tr>
</table>
<table>
<tr ng-repeat="row in $ctrl.boardArr">
<td ng-repeat="col in row>{{col}}</td>
</tr>
</table>
例如,通过像这样使用嵌套的ng repeat指令
var-app=angular.module('app',[]);
app.controller('myController',函数($scope){
$scope.myArr=[
[1,6,3],
[5,2,7],
[9,10,11],
];
});代码>
备选标题1
备选标题2
备选标题3
{{val}}
您熟悉angular中的控制器视图模型机制吗?不要重复:)问题出在哪里?当您的问题没有包含任何代码时,我开始详细说明答案。您已经编辑了上面的代码。我希望它能帮助你。你的解释是显示我的错误的最好方式。