`

Ext工具栏菜单_wayfoon

阅读更多

今天,帮群友解决了一个动态的 Ext工具栏菜单问题。

工具栏菜单数据是从后台读取的。效果如图:

工具栏效果

这里将群友提供的后台数据简化一下,改成本地读取json数据格式;

代码如下:直接copy下面代码,保存成htm文件,导入ext包,可以运行;注意文件保存编码格式(非传输编码):utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Ext工具栏菜单_wayfoon </title>
<link rel="stylesheet" type="text/css" href="ext22/resources/css/ext-all.css" />
<script type="text/javascript" src="ext22/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext22/ext-all.js"></script>
<script type="text/javascript" src="ext22/ext-lang-zh_CN.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>

<body>


<script>
Ext.onReady(function(){
var bd = Ext.getBody();
var tb=new Ext.Toolbar();

//加载Menu数据源 简化的
var menuStr = '{root:[{"MenuItemId":1000,"PMenuItemId":0,"MenuItemName":"谐波监测点","MenuItemHref":"","ChildHmMenuList":[{"MenuItemId":10001,"PMenuItemId":1000,"MenuItemName":"用户谐波源管理","MenuItemHref":"","ChildHmMenuList":null},{"MenuItemId":10002,"PMenuItemId":1000,"MenuItemName":"检测终端维护","MenuItemHref":"","ChildHmMenuList":null},{"MenuItemId":10003,"PMenuItemId":1000,"MenuItemName":"监测点属性维护","MenuItemHref":"","ChildHmMenuList":null},{"MenuItemId":10004,"PMenuItemId":1000,"MenuItemName":"监测点拓扑维护","MenuItemHref":"","ChildHmMenuList":null}]},{"MenuItemId":1001,"PMenuItemId":0,"MenuItemName":"谐波分析","MenuItemHref":"","ChildHmMenuList":[{"MenuItemId":10011,"PMenuItemId":1001,"MenuItemName":"谐波电压分析","MenuItemHref":"","ChildHmMenuList":null},{"MenuItemId":10012,"PMenuItemId":1001,"MenuItemName":"谐波电流分析","MenuItemHref":"","ChildHmMenuList":null},{"MenuItemId":10013,"PMenuItemId":1001,"MenuItemName":"越限告警事项","MenuItemHref":"","ChildHmMenuList":null},{"MenuItemId":10014,"PMenuItemId":1001,"MenuItemName":"谐波数据报表","MenuItemHref":"","ChildHmMenuList":null}]},{"MenuItemId":1002,"PMenuItemId":0,"MenuItemName":"谐波高级分析","MenuItemHref":"","ChildHmMenuList":[{"MenuItemId":10021,"PMenuItemId":1002,"MenuItemName":"谐波趋势分析","MenuItemHref":"","ChildHmMenuList":null},{"MenuItemId":10022,"PMenuItemId":1002,"MenuItemName":"潮流计算","MenuItemHref":"","ChildHmMenuList":null},{"MenuItemId":10023,"PMenuItemId":1002,"MenuItemName":"谐波源定位","MenuItemHref":"","ChildHmMenuList":null}]},{"MenuItemId":1003,"PMenuItemId":0,"MenuItemName":"系统管理","MenuItemHref":"","ChildHmMenuList":[{"MenuItemId":10031,"PMenuItemId":1003,"MenuItemName":"组织结构管理","MenuItemHref":"","ChildHmMenuList":null},{"MenuItemId":10032,"PMenuItemId":1003,"MenuItemName":"权限管理","MenuItemHref":"","ChildHmMenuList":null},{"MenuItemId":10033,"PMenuItemId":1003,"MenuItemName":"谐波限值管理","MenuItemHref":"","ChildHmMenuList":null}]}]}';

var menuObj = eval("(" + menuStr + ")");
//alert(menuObj.root);
var panel=new Ext.Panel({
title:"wayfoon",
width:400,
height:200,
tbar:tb,
html:"<div>Paele里面的内容<br>wayfoon 南极光</div>",
renderTo: bd
});

//var tbItem;
var childmenu;

Ext.each(menuObj.root,function(item) {
childmenu = new Ext.menu.Menu();

Ext.each(item.ChildHmMenuList,function(childItem) {
childmenu.add(
{
text: childItem.MenuItemName, //菜单项的文本,
href: childItem.MenuItemHref, //指定链接地址
hrefTarget: "_blank" //链接打开的发式,在新窗口打开
});
}); //end childitem

tb.add({ text: item.MenuItemName, menu: childmenu });

});


});
</script>


</body>
</html>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics