How would I use AngularJS ng-repeat with Twitter Bootstrap's scaffolding?

前端 未结 5 1997
既然无缘
既然无缘 2020-12-24 12:39

How would I use AngularJS ng-repeat to display the following HTML (Twitter Bootstrap Scaffolding)? Essentially, every third record I need to close the <

5条回答
  •  我在风中等你
    2020-12-24 13:03

    To keep view logic out of the controller and have a more re-usable solution, you can create a custom filter that splits the array into row groups:

    angular.module('app').filter('group', function() {
        /**
         * splits an array into groups of the given size
         * e.g. ([1, 2, 3, 4, 5], 2) -> [[1, 2], [3, 4], [5]]
         */
        return function(array, groupSize) {
            return _.groupBy(array, function(val, index) {
                return Math.floor(index / groupSize);
            });
        };
    });
    

    And in the view:

    {{project}}

    To include the hr you can use the ng-repeat start and end points:

    {{project}}

提交回复
热议问题