我试图制作ui bootstrap collapse
。当我使用静态单折叠或双折叠系统时,它的工作正常,但对于我的设计,我使用ng-repeat
来创建折叠,所以我不知道如何使用多次折叠,
我找到了这段代码,但它只适用于静态代码,
var app = angular.module("MyApp", ['ui.bootstrap']);
app.controller('mainController', function ($scope) {
$scope.trafficCollapsed = false;
$scope.urlCollapsed = false;
$scope.toggleUrl = function () {
$scope.urlCollapsed = false;
$scope.trafficCollapsed = !$scope.trafficCollapsed
};
$scope.toggleTraffic = function () {
$scope.trafficCollapsed = false;
$scope.urlCollapsed = !$scope.urlCollapsed;
};
});
HTML
<tr>
<td>/<span class="pull-right" ng-click="toggleUrl()">▼</span></td>
<td>A beautiful title</td>
<td>A beautiful description</td>
<td>54,654<span class="pull-right" ng-click="toggleTraffic()">▼</span
</td>
</tr>
我希望这个设计崩溃。
答案 0 :(得分:2)
<body ng-app="my_app">
<div ng-controller="CollapseDemoCtrl">
<ul class="nav">
<li ng-repeat="(key,val) in menuArray">
<button class="btn" ng-click="val.isMenuCollapsed = !val.isMenuCollapsed">{{val.button}}
<span class="caret"></span></button>
<ul class="dropdown-links" collapse="val.isMenuCollapsed">
<li ng-repeat="link in val.links" role="menuitem">
<a href="#">{{link.title}}</a>
</li>
</ul>
</li>
</ul>
</div>
风格
.nav>li {
display: inline !important;
position:relative;
}
.dropdown-links{
position: absolute;
left: 0;
z-index: 1000;
float: left;
min-width: 100%;
padding: 5px;
margin: 2px 0 0;
font-size: 14px;
text-align: left;
list-style: none;
background-color: #fff;
-webkit-background-clip: padding-box;
background-clip: padding-box;
border: 1px solid #ccc;
border: 1px solid rgba(0,0,0,.15);
border-radius: 4px;
-webkit-box-shadow: 0 6px 12px rgba(0,0,0,.175);
box-shadow: 0 6px 12px rgba(0,0,0,.175);
}
控制器代码
var my_app = angular.module('my_app', ['ui.bootstrap']);
my_app.controller('CollapseDemoCtrl', function ($scope) {
$scope.menuArray = [
{'button':'Button1','isMenuCollapsed':true,'links':[{'title':'link1-1'},{'title':'link1-2'}]},
{'button':'Button2','isMenuCollapsed':true,'links':[{'title':'link2-1'},{'title':'link2-2'}]}
];
console.log($scope.menuArray);
});