jquery的ztree插件的使用(完成动态加载树型结构)

第一步:在left.jsp中

<script language="JavaScript" src="${pageContext.request.contextPath }/script/jquery-1.4.2.js"></script>

<script language="JavaScript" src="${pageContext.request.contextPath }/script/jquery-ztree-2.5.js"></script>

<script language="JavaScript" src="${pageContext.request.contextPath }/script/treeMenu.js"></script>

<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath }/css/menu.css" />

<link rel="stylesheet" href="${pageContext.request.contextPath }/css/zTreeStyle/zTreeStyle.css" type="text/css">

Left.jsp中使用<ul>

<TABLE border=0 width="20">

    <TR>

        <TD width=340px align=center valign=top>

        <div class="zTreeDemoBackground">

            <ul id="menuTree" class="tree" ></ul>

        </div>     

        </TD>

    </TR>

</TABLE>

 

第二步:在treeMenu.js中定义:

var menu = {

    setting: {

        isSimpleData: true,

        treeNodeKey: "mid",

        treeNodeParentKey: "pid",

        showLine: true,

        root: {

            isRoot: true,

            nodes: []

        }

    },

    loadMenuTree:function(){

        $.post("elecMenuAction_showMenu.do",{},function(data){

            $("#menuTree").zTree(menu.setting, data);

        });

       

    }

};

 

$().ready(function(){

    menu.loadMenuTree();

});

 

第三步:在Action中添加:

public String showMenu(){

    //获取Session中存放的权限字符串(格式:aa@ab@ac

    String popedom = (String) request.getSession().getAttribute("globle_popedom");

    //1:查询当前用户所具有的功能权限,使用权限,查询权限表,返回List<ElecPopedom>

    List<ElecPopedom> list = elecRoleService.findPopedomListByUser(popedom);

    //2:将list放置到栈顶,栈顶的对象转换成json数组的形式

    ValueStackUtils.setValueStack(list);

    return "showMenu";

}

 

第四步:(hql语句嵌套查询),Service类定义:

public List<ElecPopedom> findPopedomListByUser(String popedom) {

    //hql语句和sql语句的嵌套查询

String condition = " and o.mid IN('"+popedom.replace("@", "','")+"') AND isMenu = ?";

    Object [] params = {true};

    Map<String, String> orderby = new LinkedHashMap<String, String>();

    orderby.put("o.mid", "asc");

    List<ElecPopedom> list = elecPopedomDao.findCollectionByConditionNoPage(condition, params, orderby);

    return list;

}

 

第五步:在struts.xml中添加:

<!-- 将集合压入到栈顶,集合返回页面的时候,转换成json的形式 -->

<result name="showMenu" type="json"></result>

 

posted @ 2016-07-19 12:57  kimi9py  阅读(3613)  评论(0编辑  收藏  举报