0

我在元素的分页循环中有以下手风琴(使用angular-ui-bootstrap ):

<div data-ng-repeat="m in results">
    <div class="stuff_in_the_middle">
        <accordion id="accordion_{{$index+((currentPage-1)*20)+1}}"  close-others="false">
            <accordion-group>
                [...stuff...]
            </accordion-group>
            <accordion-group>
                [...stuff...]
            </accordion-group>
            <accordion-group>
                [...stuff...]
            </accordion-group>
        </accordion>
        <span id="toggle_{{$index+((currentPage-1)*20)+1}}" onClick="openAllGroups">Toggle groups</span>
    </div>
</div>

我想知道如何通过单击切换链接一次展开所有元素。accordion-group是否可以?

4

1 回答 1

2

您可以在手风琴组上创建自己的 collapseall 指令。在此指令中,您可以将 isOpen 范围变量(由 angular-ui 创建)设置为来自父控制器和切换所有按钮的值。

编辑:在这里工作演示(http://plnkr.co/edit/JOOZek2QBSmxIj2pXCkK?p=preview

js

.controller('MyCtrl', ['$scope', function($scope) {
    $scope.opened = false;
}])

.directive('collapseall', [function() {
    return {
      restrict: 'A',
      scope: {
        collapseall: '='
      },
      link: function(scope, elem, attrs) {
        scope.$watch('collapseall', function(newval, oldval) {
          scope.isOpen = newval;
        })
      }
    }
  }
])

html

<div>
    <accordion close-others="false">
        <accordion-group heading="Item 001" collapseall="opened"> 
        </accordion-group>
        <accordion-group heading="Item 002" collapseall="opened">
        </accordion-group>
        <accordion-group heading="Item 003" collapseall="opened">
        </accordion-group>
    </accordion>
    <button class="btn" ng-click="opened=!opened">Toggle groups</button>
</div>
于 2013-10-08T05:00:46.993 回答