var menuList = me.menus;//获取所有菜单
var pageMenu = [];
var buttonlis = [];
for(var i = 0; i< menuList.length; i++){
var menu = menuList[i];
var pageSubMenu = [];
var subMenuList = menuList[i].subMenus;
for(var n = 0; n < subMenuList.length; n++){
var subMenu = subMenuList[n];
buttonlis.push({id:subMenu.id,name:subMenu.name,link:subMenu.link});
pageSubMenu.push(Ext.create('Ext.Component',{
height: 5
}));
pageSubMenu.push(Ext.create('Ext.button.Button',{
id: subMenu.id,
text: subMenu.name,
textAlign: 'left',
iconAlign: 'left',
icon: 'images/folder_go.png'
}));
}
pageMenu.push(Ext.create('Ext.panel.Panel',{//创建主菜单
id: 'men' + menu.id,
collapsed: true,
title: menu.name,
iconCls: 'folder',
layout: {
type: 'vbox',
align: 'stretch'
},
items:[pageSubMenu]
}));
}
//循环为按钮添加事件
for(var j = 0; j< buttonlis.length; j++){
var lis = buttonlis[j];
var btn = Ext.getCmp(lis.id);
btn.on("click" , function(){
alert(lis.name);
});
}