隨筆-12  評論-6  文章-0  trackbacks-0
          各位如果想找合適的樹形菜單,不放試試dtree,去官網(wǎng)看看www.destroydrop.com/javascript/tree/,下載dtree.zip下來解壓之后有dtree.js,dtree.css,img文件夾,api.html,example01.html這幾個文件,可以看看api.html,里面有參數(shù)和方法說明,實(shí)際上在項目應(yīng)用時,我們是需要從數(shù)據(jù)庫里的菜單表里讀取數(shù)據(jù)進(jìn)行樹形菜單構(gòu)建的,根據(jù)api.html里面的參數(shù)說明可建立一張s_menu的數(shù)據(jù)表:
          CREATE TABLE `s_menu` (
            `id` 
          int(11NOT NULL AUTO_INCREMENT COMMENT '主鍵id',
            `pid` 
          int(11DEFAULT NULL COMMENT '父級id',
            `name` 
          varchar(45DEFAULT NULL COMMENT '菜單名稱',
            `url` 
          varchar(255DEFAULT NULL COMMENT '菜單url',
            `title` 
          varchar(45DEFAULT NULL COMMENT '鼠標(biāo)放上去顯示的title',
            `target` 
          varchar(45DEFAULT NULL COMMENT '目標(biāo)iframe',
            `icon` 
          varchar(255DEFAULT NULL COMMENT '菜單折疊時候顯示的圖片',
            `iconOpen` 
          varchar(255DEFAULT NULL COMMENT '菜單打開時候顯示的圖片',
            `
          openint(1DEFAULT '0' COMMENT '是否打開',
            
          PRIMARY KEY (`id`)
          ) ENGINE
          =MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;

          并且插入一些測試數(shù)據(jù)來使用:
          INSERT INTO `s_menu` VALUES ('1''-1''瀏覽器''#''瀏覽器'nullnullnull'0');
          INSERT INTO `s_menu` VALUES ('2''1''IE''#''IE瀏覽器'nullnullnull'0');
          INSERT INTO `s_menu` VALUES ('3''2''IE6''#''IE6'nullnullnull'0');
          INSERT INTO `s_menu` VALUES ('4''2''IE7''#''IE7'nullnullnull'0');
          INSERT INTO `s_menu` VALUES ('5''2''IE8''#''IE8'nullnullnull'0');
          INSERT INTO `s_menu` VALUES ('6''2''IE10''#''IE10'nullnullnull'0');
          INSERT INTO `s_menu` VALUES ('7''1''Firefox''#''Firefox'nullnullnull'0');
          INSERT INTO `s_menu` VALUES ('8''7''Firefox15.0''#''Firefox15.0'nullnullnull'0');
          INSERT INTO `s_menu` VALUES ('9''7''Firefox15.1''#''Firefox15.1'nullnullnull'0');
          INSERT INTO `s_menu` VALUES ('10''1''360瀏覽器''#''360瀏覽器'nullnullnull'0');
          INSERT INTO `s_menu` VALUES ('11''1''搜狗瀏覽器''#''搜狗瀏覽器'nullnullnull'0');

          接下來把解壓好的dtree.js以及dtree.css放到項目的對應(yīng)目錄下,并在頁面引入,后臺執(zhí)行方法我就不說了,就是查詢出s_menu里所有的數(shù)據(jù)就可以了,在jsp里面實(shí)現(xiàn):
          <%@ page contentType="text/html;charset=UTF-8" %>
          <%@ include file="/common/taglibs.jsp" %>
          <%@ page import="org.springframework.context.ApplicationContext,org.springframework.context.support.ClassPathXmlApplicationContext,com.zx.ww.entity.base.Menu,com.zx.ww.service.base.MenuManager,java.util.List"  %>
          <%
              ApplicationContext context 
          = new ClassPathXmlApplicationContext("applicationContext.xml");
              MenuManager menuManager 
          = (MenuManager)context.getBean("menuManager");
              List
          <Menu> menus = menuManager.findAllMenu();
              request.setAttribute(
          "menus", menus);
          %>
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
              
          <head>
                  
          <title>SSH2</title>
              
          </head>
              
          <body>
                  
          <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                      
          <tr>
                          
          <td valign="top">
                              
          <div id="treearea" style="overflow: scroll;height:100%;width:100%"></div>
                          
          </td>
                      
          </tr>
                  
          </table>
              
          </body>
          </html>
          <script type="text/javascript">
              
          var dtree = new dTree('dtree', '${ctx}/images/dtree/');
              dtree.config.folderLinks 
          = true;
              dtree.config.useCookies 
          = true;
              
          <c:forEach items="${menus}" var="menu">
                  dtree.add(${menu.id},${menu.pid},
          "${menu.name}","${menu.url}","${menu.title}");
              
          </c:forEach>
              document.getElementById('treearea').innerHTML 
          = dtree;
              
          </script>

          看效果:

          這是從數(shù)據(jù)庫里讀出數(shù)據(jù)的方式,本地的話構(gòu)建這樣的數(shù)據(jù)就行了:
          <script type="text/javascript">
                  
          <!--

                  d 
          = new dTree('d');

                  d.add(
          0,-1,'My example tree');
                  d.add(
          1,0,'Node 1','example01.html');
                  d.add(
          2,0,'Node 2','example01.html');
                  d.add(
          3,1,'Node 1.1','example01.html');
                  d.add(
          4,0,'Node 3','example01.html');
                  d.add(
          5,3,'Node 1.1.1','example01.html');
                  d.add(
          6,5,'Node 1.1.1.1','example01.html');
                  d.add(
          7,0,'Node 4','example01.html');
                  d.add(
          8,1,'Node 1.2','example01.html');
                  d.add(
          9,0,'My Pictures','example01.html','Pictures I\'ve taken over the years','','','img/imgfolder.gif');
                  d.add(
          10,9,'The trip to Iceland','example01.html','Pictures of Gullfoss and Geysir');
                  d.add(
          11,9,'Mom\'s birthday','example01.html');
                  d.add(
          12,0,'Recycle Bin','example01.html','','','img/trash.gif');

                  document.write(d);

                  
          //-->
              </script>
          網(wǎng)上有很多關(guān)于dtree的說明,在此看不明白的再去網(wǎng)上找找別的,有說的比較詳細(xì)的PPT,關(guān)于各個參數(shù)以及方法說明都有~
          ok,留著以后會有用的!
          posted on 2014-05-30 17:46 小人物_Amor 閱讀(1264) 評論(0)  編輯  收藏 所屬分類: web
          主站蜘蛛池模板: 弋阳县| 桑日县| 德兴市| 玛多县| 香河县| 大厂| 永福县| 来安县| 鄂温| 大田县| 大渡口区| 顺平县| 乐亭县| 陇南市| 延边| 乳源| 赫章县| 吕梁市| 南通市| 宝清县| 朔州市| 无锡市| 正镶白旗| 肥乡县| 赞皇县| 富源县| 周宁县| 繁峙县| 永靖县| 海盐县| 朝阳区| 施甸县| 阳高县| 汕头市| 台北县| 盱眙县| 鄂州市| 高尔夫| 阜宁县| 双辽市| 永泰县|