如何 ng-repeat
带字符串索引的数组?请参阅下面的代码片段 -
下面的代码在控制器中。
$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>
原文由 anand patil 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以只对数组中的项目使用普通语法。请参考我的小提琴
https://jsfiddle.net/DoTH/evcv4tu5/3/