87,907
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
// 创建 JSONSTORE
var menuStore =new Ext.data.JsonStore({
url : 'loadRoleMenus.do',
root:'records',
fields:['code','name','jspurl','isLeaf','parentcode'],
autoLoad : true
});
// 加载数据
menuStore.on('load', function(_store, _records, _options){
for (var i = 0; i < _records.length; i++) {
var parentcode= _records[i].get('parentcode');
if (Ext.isEmpty(parentcode)){
addRootMenu(_records[i]);
}else{
continue;
}
}
});
// 添加根菜单
function addRootMenu(node) {
//Get XmlString
var sXmlString = "";
var sBegin = "<root><menu><ul>";
var sEnd = "</ul></menu></root>";
sXmlString = sBegin + getChildXmlString(node.data.code) + sEnd;
addMainMenu(node.data.name, sXmlString); // 添加根菜单
}
// 获取单个根菜单下的所有子菜单栏的 XML 字符串
function getChildXmlString(strParent) {
var sMenuItem = ""
var sLeft = "<li onclick=";
sLeft += '"';
sLeft += "{fnCallJspFuncPage('";
var sCenter = "')}";
sCenter += '">';
var sRight = "</li>";
for (var i = 0; i < menuStore.getCount(); i++) {
if (menuStore.getAt(i).data.parentcode==strParent) {
sMenuItem = sMenuItem + sLeft + menuStore.getAt(i).data.jspurl + sCenter + menuStore.getAt(i).data.name + sRight;
}
}
return sMenuItem;
}
// welcome.js end
// 将来想扩展成动态的数组对象,目前数组固定为 6 个元素
var arrMenuMain = new Array(6);
var intMenuIndx = 1;
arrMenuMain[0] = new Menu();
arrMenuMain[0].id = "MenuA";
arrMenuMain[1] = new Menu();
arrMenuMain[1].id = "MenuB";
arrMenuMain[2] = new Menu();
arrMenuMain[2].id = "MenuC";
arrMenuMain[3] = new Menu();
arrMenuMain[3].id = "MenuD";
arrMenuMain[4] = new Menu();
arrMenuMain[4].id = "MenuE";
arrMenuMain[5] = new Menu();
arrMenuMain[5].id = "MenuF";
// 添加根菜单的处理函数
function addMainMenu(strMenuItemText, strXmlString){
var tdMnu = document.getElementById("rowMenuMain").insertCell();
var sID = "Menu" + String.fromCharCode(intMenuIndx+64);
tdMnu.Id = "TD-" + sID;
// 产生 LI对象 及其属性串
var sRes = '<li id="';
sRes += sID;
sRes += '" ';
sRes += 'onmouseover="{this.className = ';
sRes += "'over'}";
sRes += '" onmouseout=';
sRes += '"{this.className = ';
sRes += "'out'}";
sRes += '"';
sRes += " class='out'>";
sRes += strMenuItemText + "</li>";
tdMnu.innerHTML = sRes;
tdMnu.width = 100;
tdMnu.align = "center";
arrMenuMain[intMenuIndx-1].width = 180;
arrMenuMain[intMenuIndx-1].xmlString = strXmlString;
arrMenuMain[intMenuIndx-1].init();
intMenuIndx += 1;
}
// 问题就出在下面的代码:BEGIN
document.getElementById("MenuA").onmousemove = function(e) {
for (var i = 0; i <= 5; i++) {
var sItm = "Menu" + String.fromCharCode(i+65);
if (sItm=="MenuA") {
arrMenuMain[i].show(e, "left");
} else {
arrMenuMain[i].close(e);
}
}
}
// MenuB、MenuC、MenuD、MenuE、MenuF 与 MenuA 中代码相同,此处略掉
// 问题就出在下面的代码:END
// IE 中的提示是这样的“document.getElementById("...")为空,或不是对象”
</script>
</body>
</html>