pull/223/merge
xu yan 2019-02-25 04:27:56 +00:00 committed by GitHub
commit 66677b07c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 9 deletions

View File

@ -21,18 +21,27 @@
this.getMenuItems = function() {
var states = defineMenuItemStates();
var menuItems = states.filter(function(item) {
return item.level == 0;
//result shoud like [0,1,2]
var levels = states.map(function (e) {
return e.level;
}).filter(function (e, i, arr) {
return i === arr.indexOf(e);
});
menuItems.forEach(function(item) {
var children = states.filter(function(child) {
return child.level == 1 && child.name.indexOf(item.name) === 0;
//add subMenu for each level item
levels.forEach(function (level) {
var menuItems = states.filter(function (e) {
return e.level === level;
});
menuItems.forEach(function (item) {
var children = states.filter(function (child) {
return child.level - level === 1 && child.name.indexOf(item.name) === 0;
});
item.subMenu = children.length ? children : null;
});
item.subMenu = children.length ? children : null;
});
return menuItems.concat(staticMenuItems);
return states.filter(function (e) {
return e.level === 0;
}).concat(staticMenuItems);
};
this.shouldMenuBeCollapsed = shouldMenuBeCollapsed;