2015-11-09 45 views

回答

2

是的,你可以,只需用數組管理摺疊狀態。請記住,uib-collapse屬性控制元素是否摺疊。所以,你的標記看起來像:

<button type="button" class="btn btn-default" ng-click="collapseToggle(0)">Toggle collapse 0</button> 
<div uib-collapse="!isCollapsed[0]"> 
    <div class="well well-lg">Some content</div> 
</div> 
<br /> 
<button type="button" class="btn btn-default" ng-click="collapseToggle(1)">Toggle collapse 0</button> 
<div uib-collapse="!isCollapsed[1]"> 
    <div class="well well-lg">Some content</div> 
</div> 
<br /> 
<button type="button" class="btn btn-default" ng-click="collapseToggle(2)">Toggle collapse 0</button> 
<div uib-collapse="!isCollapsed[2]"> 
    <div class="well well-lg">Some content</div> 
</div> 

和控制器位:

$scope.isCollapsed = []; 

$scope.collapseToggle = function(id) { 
    // if toggeling the same collapse 
    // just close it. 
    if ($scope.isCollapsed[id]) { 
    $scope.isCollapsed.length = 0; 
    return; 
    } 
    $scope.isCollapsed.length = 0; 
    $scope.isCollapsed[id] = true; 
} 

這裏是一個展示plunk這種方法。

+0

Thanks @robj!有效! – francisaugusto