如何ng-repeat
array with string index?请看下面的代码片段-
以下代码在 Controller 中。
$scope.days = ["mon", "tue", "wed" .... "sun"];
$scope.arr = [];
$scope.arr["mon"] = ["apple","orange"];
$scope.arr["tue"] = ["blue","swish"];
.
.
.
$scope.arr["sun"] = ["pineapple","myfruit","carrot"];
问题 - 如何像下面那样ng-repeat
,这可能吗?
<div ng-repeat="day in days">{{day}}
<span ng-repeat="item in arr(day)">{{item}}</span>
<-- Something like "arr(day)", can it be done in angular -->
</div>
最佳答案
您可以只对数组中的项目使用普通语法。 请引用我的 fiddle
<div ng-app='app' ng-controller='default' ng-init='init()'>
<div ng-repeat='day in days'>
<strong>{{day}}</strong><br/>
<span ng-repeat="item in arr[day]">{{item}} </span>
</div>
</div>
关于javascript - AngularJS - ng-repeat array with string index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37228530/