我有一个方案,如果内部li列表项达到第10个选项,则必须创建一个新的ul。 例如,这里是fiddle。我有两个变量,每个变量包含许多选项。我在行div上有外部ng-repeat,在列表项li上有内部重复。由于某些设计问题,如果内部li选项达到10个计数,我必须创建一个新的ul。那是一个ul只能处理10个项目列表。如何在不影响现有变量代码的情况下动态地执行此操作。我尝试按组进行分组,但仅限于修改现有的变量数组。
这是代码
HTML
<div ng-controller="MainCtrl">
<div class="grid-list">
<div class="grid-row" ng-repeat="variable in variables track by $index">
<div class="grid_question"> {{variable.name}}
<ul class="grid-list"> /// add new ul after every 10 option, ul can contain only 10 list.
<li ng-repeat="option in variable.options track by $index">{{option.name}}</li>
</ul>
</div>
</div>
</div>
</div>
JS代码
var app = angular.module('myApp', []);
function MainCtrl($scope) {
$scope.variables = [{
name: 'List 1',
options: [{
name: 'Option 1',
value: '',
has_comment: false
}, {
name: 'Option 2',
value: '',
has_comment: false
}, {
name: 'Option 3',
value: '',
has_comment: false
}, {
name: 'Option 4',
value: '',
has_comment: false
}, {
name: 'Option 5',
value: '',
has_comment: false
}, {
name: 'Option 6',
value: '',
has_comment: false
}, {
name: 'Option 7',
value: '',
has_comment: false
}, {
name: 'Option 8',
value: '',
has_comment: false
}, {
name: 'Option 9',
value: '',
has_comment: false
}, {
name: 'Option 10',
value: '',
has_comment: false
}, {
name: 'Option 11',
value: '',
has_comment: false
}, {
name: 'Option 12',
value: '',
has_comment: false
}, {
name: 'Option 13',
value: '',
has_comment: false
}]
},
{
name: 'List 2',
options: [{
name: 'Option 1',
value: '',
has_comment: false
}, {
name: 'Option 2',
value: '',
has_comment: false
}, {
name: 'Option 3',
value: '',
has_comment: false
}, {
name: 'Option 4',
value: '',
has_comment: false
}, {
name: 'Option 5',
value: '',
has_comment: false
}, {
name: 'Option 6',
value: '',
has_comment: false
}, {
name: 'Option 7',
value: '',
has_comment: false
}, {
name: 'Option 8',
value: '',
has_comment: false
}, {
name: 'Option 9',
value: '',
has_comment: false
}, {
name: 'Option 10',
value: '',
has_comment: false
}, {
name: 'Option 11',
value: '',
has_comment: false
}, {
name: 'Option 12',
value: '',
has_comment: false
}, {
name: 'Option 13',
value: '',
has_comment: false
}]
},
]
}