Javascript 外部ng重复项影响内部ng重复逻辑的嵌套ng重复
我的代码Javascript 外部ng重复项影响内部ng重复逻辑的嵌套ng重复,javascript,angularjs,Javascript,Angularjs,我的代码 <div ng-repeat='n in [] | range:(my_works.items.length/3)+1'> <div class="table-row" style="position:absolute;left:13px;{{row_gap_style(n)}}" class='ng-scope'> <div class="book_container" ng-repeat='item in my_works.i
<div ng-repeat='n in [] | range:(my_works.items.length/3)+1'>
<div class="table-row" style="position:absolute;left:13px;{{row_gap_style(n)}}" class='ng-scope'>
<div class="book_container" ng-repeat='item in my_works.items.slice($index*3,($index*3+3))' style="position:absolute;top:0px;{{col_gap_style($index)}}">
<div id="" title="{{ item.Story.title}}" class="cover_container fetched {{check_published(item)}}" rel="<?php echo $rel; ?>">
否则,div应该与以前一样
如何实现这一点?您可以为相同的内容创建一个指令,然后使用ng if根据n的值设置不同的属性:
.directive('bookContainer', function() {
return {
scope: {
'items': '=',
'colstyle': '@'
},
restrict: 'E',
template: '<p ng-repeat="item in items">book: {{item}} {{colstyle}}</p>'
};
});
指令('bookContainer',函数(){
返回{
范围:{
“项目”:“=”,
“colstyle”:“@”
},
限制:'E',
模板:'book:{{item}}{{colstyle}}
' }; }); 视图:
演示已经大大简化,但展示了您希望使用的技术。包括两个div元素,并向这两个元素添加一个ng if指令;一个包含n==0,另一个包含n!=0.内部ng repeat中的元素如何?理想情况下,我不必重复它们。我指的是保险箱等
.directive('bookContainer', function() {
return {
scope: {
'items': '=',
'colstyle': '@'
},
restrict: 'E',
template: '<p ng-repeat="item in items">book: {{item}} {{colstyle}}</p>'
};
});
<div ng-repeat='n in []'>
<book-container ng-if='n==0' items='my_works.slice($index,1)' colstyle='s1'></book-container>
<book-container ng-if='n!=0' items='my_works.slice($index,2)' colstyle='s2'></book-container>
</div>