add bootstrap rows during ng-repeat

后端 未结 5 1991
慢半拍i
慢半拍i 2020-12-28 09:50

I have a situation where I have a list of data to be displayed in individual panels, Using Bootstrap\'s grid system, I\'d like to take advantage of a wide screen and displa

5条回答
  •  一个人的身影
    2020-12-28 10:18

    Answering my own question here, similar to the answer from j.wittwer, I created a filter to chunk my data appropriately by row, etc.:

    angular.module('myApp.filters').
        filter('rowfilter', function () {
            return function (data, columnCount) {
                var rows = [];
            var colCount = columnCount || 2;
            var columns = [];
            for (var i = 0; i< data.length; i++) {
            columns.push(data[i]);
            if (columns.length == colCount) {
            rows.push(columns);
            columns = [];
            }
            }
            if (columns.length > 0) {
            rows.push(columns);
            }
            return rows;
            };
        });
    

    And then I use the filter (jade shown here): .row(ng-repeat="row in contestData.classData | rowfilter") .col-sm-6(ng-repeat="column in row")

    Works very nicely, still wrapping my head around Angular!

提交回复
热议问题