jquery的ztree外掛程式的使用(完成動態載入樹型結構)

來源:互聯網
上載者:User

標籤:

第一步:在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中存放的許可權字串(格式:[email protected]@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>

 

jquery的ztree外掛程式的使用(完成動態載入樹型結構)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.