我正在使用 Angularjs 和 Bootstrap 2.3.2 创建带有子菜单的菜单系统。这很有效,直到我在窄设备上使用响应式设计并且菜单系统的折叠版本出现问题。具体来说,选择菜单项之一后菜单不会折叠。有趣的是,即使主菜单没有,SUB 菜单也会崩溃。如果您单击图标栏,菜单可以折叠,但菜单项本身不会这样做。
我通过 $resource 检索菜单(特定于用户),它们由以下模板创建:
<div class="navbar navbar-inverse navbar-fixed-top hidden-print">
<div class="navbar-inner">
<div class="container">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
</button>
<a class="brand" href="#">BRAND HERE</a>
<div ng-controller="MenuController" class="nav-collapse collapse">
<div ng-repeat="menu in menus">
<ul class="nav" role="navigation">
<li ng-show="menu.submenus" class="dropdown" class="active">
<a class="dropdown-toggle" href="{{menu.route}}">{{menu.title}}<i class="icon-caret-down"></i><b class="caret"></b></a>
<ul class="dropdown-menu">
<li ng-repeat="submenu in menu.submenus"><a href="{{submenu.route}}">{{submenu.title}}</a></li>
</ul>
</li>
<li ng-hide="menu.submenus"><a href="{{menu.route}}">{{menu.title}}</a></li>
</ul>
</div>
</div>
<!--/.nav-collapse -->
</div>
<!--/ container -->
</div>
</div>
<!--/ navbar -->
菜单对象看起来像这样:
[
{
"title": "Setup",
"route": "#",
"submenus": [
{
"title": "one",
"route": "#/one",
"submenus": null
},
{
"title": "two",
"route": "#/two",
"submenus": null
} ]
},
{
"title": "special",
"route": "#/special",
"submenus": null
},
{
"title": "boring",
"route": "#/boring",
"submenus": null
}
]