Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS中的二维数组_Angularjs - Fatal编程技术网

AngularJS中的二维数组

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

另一个答案是:

-

原始问题:

如何使用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 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中的控制器视图模型机制吗?不要重复:)问题出在哪里?当您的问题没有包含任何代码时,我开始详细说明答案。您已经编辑了上面的代码。我希望它能帮助你。你的解释是显示我的错误的最好方式。