繁体   English   中英

嵌套ng-repeat和外部ng-repeat项会影响内部ng-repeat逻辑

[英]nested ng-repeat with outer ng-repeat item affecting the inner ng-repeat logic

我的密码

<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; ?>">

我想做的是

如果外部ng-repeat中的n为0,则div.book_container看起来像这样:

<div class="book_container" ng-show="n == 0" ng-repeat='item in my_works.items.slice($index*2, ($index*2+2))' style="position:absolute;top:0px;{{col_gap_style($index+1)}}">

否则,div应该和以前一样。

我该如何完成?

您可以为相同的内容创建指令,然后使用ng-if根据n的值设置不同的属性:

.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>

小提琴

该演示已大大简化,但显示了您可以希望使用的技术。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM