easyui-accordion动态生成菜单的实现

       暑假无聊,突然想起期末的模拟项目还没做完,当时就准备把菜单做成动态的,可惜因为某些原因没有完成,既然记起了就花点时间做了吧,以免我忘了

      首先看完成的效果:

easyui-accordion动态生成菜单的实现_第1张图片

需求:一级菜单在登陆成功后就加载,二级菜单需用户点击一级菜单时才加载。其中第一个一级菜单下的二级菜单也在登陆成功后加载。

easyui版本:1.43

下面是前台代码:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

    
             

我后台用的java,框架用的SSH,一个aciotn用于获取一级菜单,一个action用于获取二级菜单,代码就不贴了很简单,这里贴下菜单表:

easyui-accordion动态生成菜单的实现_第2张图片

PS.学校的项目没得源码了哈,大家可以搜一搜 孙宇 easyui  我就是参考他的项目学习的easyui的!!

2018年4月20日更新,一次返回菜单josn,js加载方法...返回的菜单json格式参考:

http://www.jeasyui.net/demo/tree_data2.json

	$.ajax({
		type : 'GET',
		dataType : "json",
		url : '/menu/getMenu',
		success : function(data) {
			$.each(data, function(i, n) {// 加载父类节点及一级菜单
				var id = n.id;
				$('#layout_west_accordion').accordion('add', {
					title : n.text,
					iconCls : n.iconCls,
					selected : true,
					content : '
    ' }); // 解析整个页面 $.parser.parse(); // 第二层生成树节点 if (!n.children || n.children.length == 0) { return true; } $("#tree-" + id).tree({ data : n.children, //animate : true, lines : true,// 显示虚线效果 onClick : function(node) { if (node.attributes) { var tabTitle = node.text; var url = node.attributes.url; var openMode = node.attributes.openMode; var icon = node.iconCls; var pid = node.id; addTab(tabTitle, url, openMode,icon, pid); } } }); }); } });

    你可能感兴趣的:(easyui,accordion,动态菜单,SSH+easyui项目)