如何在ng-repeat中显示下一行的数据?

时间:2015-01-06 06:02:05

标签: javascript angularjs html5

我需要在ng-repeat循环中的下一行显示数据。但我无法找到如何做到这一点。任何人都可以建议我如何做到这一点。 JS:

 $scope.array ={dates:[]};
 $scope.array ({display:display});
 var display = day+ "\n" + date;

这里的日子=星期一,星期二等,日期包含4,5,6 ..等等。 我希望将其显示为,

MON     TUE
5       6

HTML:

<div class="col" style="border-right: solid 1px #820d13; " ng-repeat="days in array">
    <p class="delivery_date" ng-if="days.date != undefined" style="transform: rotate(270deg);margin-top: 8px;font-size: 12px;font-weight: 600;text-transform: uppercase;">
{{days.display}}
   </p></div>

3 个答案:

答案 0 :(得分:0)

&#13;
&#13;
angular.module('todoApp', []).controller('TodoController', function($scope) {
  $scope.array = {
    'date': ['Mon 5', 'Tue 6']
  };
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="todoApp" ng-controller="TodoController">
  <div ng-repeat="date in array.date">
    <p>{{date.split(' ')[0]}}
      <p>
        <p>{{date.split(' ')[1]}}
          <p>
  </div>

</div>
&#13;
&#13;
&#13;

{{ }}之间,你可以编写javascript代码,angular会解析并运行它。

答案 1 :(得分:0)

HTML:

<div ng-app="myapp" ng-controller="myctrl">
    <p ng-repeat="k in array.dates">{{ k.split(' ')[0] }} <br /> {{ k.split(' ')[1] }}</p>
</div>

脚本:

angular.module('myapp',[])
 .controller('myctrl',function($scope){
    $scope.array ={dates:['MON 5', 'TUE 6']};
 });

答案 2 :(得分:0)

请检查这是否是您所需要的。

var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
    $scope.array = ['MON  5 10', ' TUE 6 11'];
    var data = {
        headers : [],
        rows : []
    };
    var array = $scope.array;
    for(var index in array){
        data['headers'].push(array[index].trim().split(/\s+/)[0]);
        data['rows'].push(array[index].trim().split(/\s+/).splice(1))
    }

    data['rows'] = data['rows'][0].map(function(col, i) { 
      return data['rows'].map(function(row) { 
        return row[i] 
      })
    });


    $scope.data = data;
}


<div ng-controller="MyCtrl">
<div >
    <span ng-repeat="header in data.headers">{{header}}</span>
</div>
<div ng-repeat="row in data.rows">
    <div >
        <span ng-repeat="item in row">{{item}}</span>
    </div>
</div>
</div>

JS-Fiddle link