Javascript 如果有多个子菜单,是否将其设置为下拉菜单?
我正在与Mean JS合作一个项目,我正在使用他们提供的模板。 基本上我想做:Javascript 如果有多个子菜单,是否将其设置为下拉菜单?,javascript,angularjs,twitter-bootstrap,drop-down-menu,meanjs,Javascript,Angularjs,Twitter Bootstrap,Drop Down Menu,Meanjs,我正在与Mean JS合作一个项目,我正在使用他们提供的模板。 基本上我想做: if (more than 1 sub-menus) make it drop-down else make just a button and if that button clicked take it to state of the sub menu. 导航栏上的按钮将定义为下拉菜单。它将有两个子菜单。此主按钮将对所有类型的用户可见。但是,普通用户只能看到下拉菜单上
if (more than 1 sub-menus)
make it drop-down
else
make just a button and if that button clicked take it to state of the sub menu.
导航栏上的按钮将定义为下拉菜单。它将有两个子菜单。此主按钮将对所有类型的用户可见。但是,普通用户只能看到下拉菜单上的一个子菜单。所有2个子菜单将对管理员用户可见。我想将其定义为下拉菜单,但如果只有1个子菜单,则不要将其显示为下拉菜单。当用户单击主按钮时,它将进入子菜单中定义的页面
下面是header.client.view.html中的代码(这是模板中的代码,我没有更改它)
<nav class="collapse navbar-collapse" collapse="!isCollapsed" role="navigation">
<ul class="nav navbar-nav" ng-if="menu.shouldRender(authentication.user);">
<li ng-repeat="item in menu.items | orderBy: 'position'" ng-if="item.shouldRender(authentication.user);" ng-switch="item.type" ng-class="{ active: $state.includes(item.state), dropdown: item.type === 'dropdown' }" class="{{item.class}}" dropdown="item.type === 'dropdown'">
<a ng-switch-when="dropdown" class="dropdown-toggle" dropdown-toggle role="button">{{::item.title}} <span class="caret"></span></a>
<ul ng-switch-when="dropdown" class="dropdown-menu">
<li ng-repeat="subitem in item.items | orderBy: 'position'" ng-if="subitem.shouldRender(authentication.user);" ui-sref-active="active">
<a ui-sref="{{subitem.state}}" ng-bind="subitem.title"></a>
</li>
</ul>
<a ng-switch-default ui-sref="{{item.state}}" ng-bind="item.title"></a>
</li>
</ul>
</nav>
// Configuring the Articles module
angular.module('articles').run(['Menus',
function(Menus) {
// Add the articles dropdown item
Menus.addMenuItem('topbar', {
title: 'Blog',
state: 'articles',
type: 'dropdown',
roles: ['*'],
position: 1
});
// Add the dropdown list item
Menus.addSubMenuItem('topbar', 'articles', {
title: 'Visit Blog',
state: 'articles.list',
roles: ['user', 'admin']
});
// Add the dropdown create item
Menus.addSubMenuItem('topbar', 'articles', {
title: 'Create Blog Post',
state: 'articles.create',
roles: ['admin']
});
}
]);