Javascript AngularJs:ng repeat=";“arrayValue”中的项目;

Javascript AngularJs:ng repeat=";“arrayValue”中的项目;,javascript,angularjs,Javascript,Angularjs,我有以下数组: var date = { '2015': [{ 'month': 'Januar', 'day': 31 }, { 'month': 'Februar', 'day': 28 }] }; 我想让ng重复等于天数: 所需产出: <div ng-repeat="date in date.2015"> {{date.month}} <!-- Displays 12 month name -->

我有以下数组:

 var date = {
   '2015': [{
     'month': 'Januar',
     'day': 31
   }, {
     'month': 'Februar',
     'day': 28
   }]
 };
我想让ng重复等于天数:
所需产出:

<div ng-repeat="date in date.2015">
  {{date.month}}
  <!-- Displays 12 month name -->
  <div ng-repeat="day in date.2015+{{$index}}+'.day'">
    {{day}}
    <!-- displays 31, 30 or 28 times the day -->
    <!-- The day should also increment from 0 to the number -->
  </div>
</div>

{{date.month}
{{day}
我希望这是清楚的。

ng repeat=“day in date.2015+{{$index}}+'.day'
不起作用

我希望你想做的事情我都做对了。要重复这些天,请执行以下操作:

<div ng-repeat="date in date.2015">
   {{date.month}} <!-- Displays 12 month name -->
   <div ng-repeat="day in getDays(date.day)">
        {{day}} <!-- displays 31, 30 or 28 times the day -->
        <!-- The day should also increment from 0 to the number -->
   </div>
</div>

首先,控制器中需要一个helper函数,用于将数字转换为一个长度等于一天值的数组:

$scope.range = function(n) {
    return new Array(n);   
}
如果使用的是angular的最新版本,则需要在repeat to alias中显式设置一个变量


他给了我一个错误。使用
ng repeat=“day in date.2015[0].day”
时,元素不会重复,但不会出现错误使用@gr3g更新的答案&带有最新角度示例的代码片段非常感谢您的答案。如果有兴趣,请在此处说明以下问题:
$scope.range = function(n) {
    return new Array(n);   
}
<div ng-repeat="date in date.2015">
   {{date.month}} <!-- Displays 12 month name -->
   <div ng-repeat="day in range(date.day) track by $index">
        {{$index + 1}} <!-- displays 31, 30 or 28 times the day -->
        <!-- The day should also increment from 0 to the number -->
   </div>
</div>
<div ng-repeat="date in date.2015">
   {{date.month}} <!-- Displays 12 month name -->
   <div ng-repeat="day in range(date.day)">
        {{$index + 1}} <!-- displays 31, 30 or 28 times the day -->
        <!-- The day should also increment from 0 to the number -->
   </div>
</div>