Fix Sidebar Service

Fix Sidebar Service not getting second level state menu item
pull/337/head
djpeace 2017-09-07 22:55:22 +08:00 committed by GitHub
parent 1f81f3b1c1
commit 1d3b60437a
1 changed files with 16 additions and 12 deletions

View File

@ -19,20 +19,24 @@
function _factory() { function _factory() {
var isMenuCollapsed = shouldMenuBeCollapsed(); var isMenuCollapsed = shouldMenuBeCollapsed();
this.getMenuItems = function() { this.getMenuItems = function () {
var states = defineMenuItemStates(); var states = defineMenuItemStates();
var menuItems = states.filter(function(item) { var zeroLevels = states.filter(function (zeroLevelStateItem) {
return item.level == 0; return zeroLevelStateItem.level == 0;
}); });
zeroLevels.forEach(function (zeroLevel) {
menuItems.forEach(function(item) { var firstLevels = states.filter(function (firstLevelStateItem) {
var children = states.filter(function(child) { return firstLevelStateItem.level == 1 && firstLevelStateItem.name.indexOf(zeroLevel.name) === 0;
return child.level == 1 && child.name.indexOf(item.name) === 0;
}); });
item.subMenu = children.length ? children : null; firstLevels.forEach(function (firstLevel) {
var secondLevel = states.filter(function (secondLevelStateItem) {
return secondLevelStateItem.level == 2 && secondLevelStateItem.name.indexOf(firstLevel.name) === 0;
}); });
firstLevel.subMenu = secondLevel.length ? secondLevel : null;
return menuItems.concat(staticMenuItems); });
zeroLevel.subMenu = firstLevels.length ? firstLevels : null;
});
return zeroLevels.concat(staticMenuItems);
}; };
this.shouldMenuBeCollapsed = shouldMenuBeCollapsed; this.shouldMenuBeCollapsed = shouldMenuBeCollapsed;