У меня такой массив:
$scope.first = [ [ [ "a", "b", "c" ], [ "d", "e", "f" ] ], [ [ "g", "h", "i" ], [ "g", "k", "l" ] ], [ [ "m", "n", "o" ], [ "p", "q", "r" ] ], [ [ "s", "t", "w" ], [ "x", "y", "z" ] ] ];
Я вложен ng-repeat:
<div ng-repeat="seconds in first">
<div ng-repeat="thirds seconds">
<div ng-repeat="item in thirds">
<span>{{item}}</span>
</div>
</div>
</div>
и я хочу отобразить
1-а
2-б
3-с
4-д
5-е
........
25-й
Я очень ценю вашу помощь.
Попробуйте это (html-решение)
(function ()
{
var app = angular.module("app", []);
function HomeController()
{
var vm = this;
vm.first = [
[
["a", "b", "c"],
["d", "e", "f"]
],
[
["g", "h", "i"],
["g", "k", "l"]
],
[
["m", "n", "o"],
["p", "q", "r"]
],
[
["s", "t", "w"],
["x", "y", "z"]
]
];
}
app.controller("HomeController", [HomeController]);
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
<meta charset="UTF-8">
<title>Angular JS App</title>
</head>
<body>
<div class="container" ng-controller="HomeController as homeCtrl">
<div ng-repeat="(firstIndex, seconds) in homeCtrl.first" ng-init="i = firstIndex">
<div ng-repeat="(secondIndex, thirds) in seconds" ng-init="j = i * seconds.length+secondIndex">
<div ng-repeat="(thirdIndex, item) in thirds" ng-init="k = j * thirds.length+thirdIndex">
<span>{{k+1}}-{{item}}</span>
</div>
</div>
</div>
</div>
</body>
</html>
Я думаю, что это может быть то, что вы ищете, хотя мое конечное значение как 24-z, а не 25-y, так что что-то пошло не так.
Ниже HTML сторона (FYI вы пропустили in
во второй ng-repeat
вызова
{{ setCounterToZero() }}
<div ng-repeat="seconds in first">
<div ng-repeat="thirds in seconds">
<div ng-repeat="item in thirds">
<span>{{ outputItem(item) }}</span>
<br />
</div>
</div>
</div>
И вот код для контроллера
$scope.first = [
[
["a", "b", "c"],
["d", "e", "f"]
],
[
["g", "h", "i"],
["g", "k", "l"]
],
[
["m", "n", "o"],
["p", "q", "r"]
],
[
["s", "t", "w"],
["x", "y", "z"]
]
];
$scope.counterValue = 0;
$scope.setCounterToZero = function () {
$scope.counterValue = 0;
}
$scope.outputItem = function (item) {
$scope.counterValue++;
return $scope.counterValue + '-' + item;
}
Это то, что вы ищете?
json
добавив также индекс для каждой буквы ?!