iterate over chunks of an array using ng-repeat

后端 未结 3 1495
离开以前
离开以前 2020-12-19 19:39

My controller grabs people from the server:

$scope.people = [person1, person2, person3, person4, person5,...]

My template needs to display

3条回答
  •  时光取名叫无心
    2020-12-19 19:58

    Here is my current solution (It's O(N^2) so doesn't scale for large lists).

    Template:

    {{item}}

    Controller:

    angular.module('myapp', []);
    
    function testing($scope){
        $scope.items = ['a', 'b', 'c', 'd','e','f','g'];
    }
    

    Result:

    a b c
    d e f
    g
    

    Fiddle:

    http://jsfiddle.net/LjX3m/

    Conclusion:

    I'll probably try use CSS for this as @aaronfrost mentions. (However it may not be possible since some wrapping divs may be required for each chunk).

提交回复
热议问题