remove - javascript arraylist



用於多維數組的嵌套ng-repeat (1)

工作示例:

HTML:

<!DOCTYPE html>
<html ng-app="plunker">

<head>
  <meta charset="utf-8" />
  <title>AngularJS Plunker</title>
  <script>
    document.write('<base href="' + document.location + '" />');
  </script>
  <script data-require="[email protected]" src="https://code.angularjs.org/1.4.9/angular.js" data-semver="1.4.9"></script>
  <script src="app.js"></script>
</head>

<body ng-controller="MainCtrl">
  <p>Hello {{name}}!</p>
  <div>
    <table>
      <tr ng-repeat="y in grid">
        <td ng-repeat="x in y track by $index">{{x}}</td>
      </tr>
    </table>
  </div>
</body>

</html>

JS:

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
  $scope.grid = [["empty", "empty", "empt", "empt", "empty"],
                  ["empty", "empty", "empt", "empt", "empty"]];
});

演示: http : //plnkr.co/edit/yVC5nrH5Pv3Zzp8Py7FH?p=preview

由於你的數組數據包含重複,所以你想添加獨特的id的track by所以我已經添加track by $index更多關於這個https://docs.angularjs.org/error/ngRepeat/dupes

我正在嘗試使用ng-repeat指令在html中顯示二維數組 。 我可以顯示第一維(表行),但第二個(表數據)不工作。 我已經看到了很多使用對象,JSON,鍵值數據結構的解決方案...但是我找不到僅僅包含其他數組的數組 。 這裡有一些不成功的嘗試。

HTML:(不起作用)

<div ng-app = "grid" ng-controller = "gridCtrl">
    <table>
        <tr ng-repeat = "y in grid">
            <td ng-repeat = "x in y"></td>
        </tr>
    </table>
</div>


HTML :(不起作用)

<div ng-app = "grid" ng-controller = "gridCtrl">
    <table>
        <tr ng-repeat = "y in grid">
            <td ng-repeat = "x in grid[$index]"></td>
        </tr>
    </table>
</div>


JS:

var grid = angular.module("grid", []);
grid.controller("gridCtrl", function($scope)
{
    $scope.grid = [[empty, empty, empty, empty, empty],
                   [empty, empty, empty, empty, empty],
                   [empty, empty, empty, empty, empty],
                   [empty, empty, empty, empty, empty],
                   [empty, empty, empty, empty, empty]];
});




multidimensional-array