81,122
社区成员




<div data-options="region:'west',split:true,title:'导航栏'" style="width:200px;">
<div id="navAccordion">
</div>
</div>
$(function() {
var location = (window.location + '').split('/');
var basePath = location[0] + '//' + location[2] + '/' + location[3];
var rootUrl = basePath + "/menu/init?parentId=0";
var childUrl = basePath + "/menu/queryMenu?parentId=";
jQuery("#navAccordion").accordion({ // 初始化accordion
fillSpace : true,
fit : true,
border : false,
animate : true
});
$.post(rootUrl, // 获取第一层目录
function(data) {
if (data == "0") {
window.location = "/login";
}
$.each(data, function(i, e) {// 循环创建手风琴的项
// console.info(Object);
var id = e.menuId;
$('#navAccordion').accordion('add', {
title : e.menuName,
content : "<ul id='tree" + id + "' ></ul>",
selected : true,
iconCls : Object.iconCls
});
// $.parser.parse();
$.post(childUrl + id, function(data) {// 循环创建树的项
console.info(data);
$("#tree" + id).tree(
{
data : data,
onBeforeExpand : function(node, param) {
$("#tree" + id).tree('options').url = childUrl
+ node.id;
},
onClick : function(node) {
var tabTitle = node.text;
var url = basePath + node.attributes;
var icon = node.iconCls;
if (node.state == 'closed') {
$(this).tree('expand', node.target);
} else if (node.state == 'open') {
$(this).tree('collapse', node.target);
} else {
addTab(tabTitle, url, icon);
}
}
});
console.info(1111111);
}, 'json');
});
}, "json");
});
function addTab(title, url, icon) {
if ($('#tabs').tabs('exists', title)) {
$('#tabs').tabs('select', title);
} else {
$('#tabs').tabs('add', {
title : title,
closable : true,
href : url
});
}
}
/**根菜单初始化*/
@RequestMapping(value="/init")
@ResponseBody
public List<Menu> menuInit(HttpServletRequest request, HttpServletResponse response) {
String parentId = "0";
System.out.println(request.getParameter("parentId"));
Menu rootMenu = new Menu();
rootMenu.setParentId(parentId);
List<Menu> rootList = menuServiceImpl.selectByCondition(rootMenu);
System.out.println("rootlist size======"+rootList.size());
return rootList;
}
/**根据条件查询节点*/
@RequestMapping(value="/queryMenu")
@ResponseBody
public List<UIMenuModel> queryMenu(HttpServletRequest request, HttpServletResponse response) {
String menuId = request.getParameter("menuId");
String parentId = request.getParameter("parentId");
Menu menu = new Menu();
if(CommonUtil.stringIsNotNull(menuId)) {
menu.setMenuId(Long.parseLong(menuId));
}
if(CommonUtil.stringIsNotNull(parentId)) {
menu.setParentId(parentId);
}
List<Menu> list = menuServiceImpl.selectByCondition(menu);
List<UIMenuModel> menuList = new ArrayList<UIMenuModel>();
if(CommonUtil.listIsNotNull(list)) {
for(int i=0; i<list.size(); i++) {
menu = list.get(i);
UIMenuModel uiMenuMode = new UIMenuModel();
uiMenuMode.setId(menu.getMenuId());
uiMenuMode.setText(menu.getMenuName());
uiMenuMode.setIconCls(menu.getIcon());
uiMenuMode.setAttributes(menu.getUrl());
//0表示不可展开是终节点,1代表可以展开有子菜单
uiMenuMode.setState(menu.getCanExpand() == "0" ? "closed":"open");
menuList.add(uiMenuMode);
}
}
System.out.println("rootlist size======"+menuList.size());
return menuList;
}