dtree的使用方法

1.創建樹的一個實例。

  這裏需要引入dtree.js和dtree.css,可通過修改css文件定製自己想要的樣式。

  1. <script type="text/javascript"
  2. <!-- 
  3.   d = new dTree('d'); 
  4.   //add(id, pid, name, url, title, target, icon, iconOpen, open) 
  5.   d.add(0, -1, ''); 
  6.   d.add(2, 1, '概況''media/all''概況'); 
  7. ...
  8. ...
  9.  
  10.   document.write(d); 
  11.  
  12.   d.openAll(); 
  13.  
  14.   /** 自動定位到id爲2的節點 */ 
  15.   d.openTo(2, true); 
  16. //--> 
  17. </script> 

2.一些重要的配置:

  1. // Tree object
  2.  
  3. //變量 類型 默認值 描述
  4. //target string 所有節點的target
  5. //folderLinks bool true 文件夾可被鏈接
  6. //useSelection bool true 節點可被選擇高亮
  7. //useCookies bool true 樹可以使用cookie記住狀態
  8. //useLines bool true 創建帶結構連接線的樹
  9. //useIcons bool true 創建帶有圖表的樹
  10. //useStatusText bool false 用節點名替代顯示在狀態欄的節點url
  11. //closeSameLevel bool false 同級節點只允許一個節點處於打開狀態
  12. //inOrder bool false 加速父節點樹的顯示
  13.  
  14. function dTree(objName) { 
  15.     this.config = { 
  16.         target              : null
  17.         folderLinks         : true
  18.         useSelection        : true
  19.         useCookies          : true
  20.         useLines            : true
  21.         useIcons            : true
  22.         useStatusText       : false
  23.         closeSameLevel   : false
  24.         inOrder             : false 
  25.     } 
  26.     this.icon = { 
  27.         root                : './js/tree/img/base.gif'
  28.         folder          : './js/tree/img/folder.gif'
  29.         folderOpen  : './js/tree/img/folderopen.gif'
  30.         node                : './js/tree/img/page.gif'
  31.         empty               : './js/tree/img/empty.gif'
  32.         line                : './js/tree/img/line.gif'
  33.         join                : './js/tree/img/join.gif'
  34.         joinBottom  : './js/tree/img/joinbottom.gif'
  35.         plus                : './js/tree/img/plus.gif'
  36.         plusBottom  : './js/tree/img/plusbottom.gif'
  37.         minus               : './js/tree/img/minus.gif'
  38.         minusBottom : './js/tree/img/minusbottom.gif'
  39.         nlPlus          : './js/tree/img/nolines_plus.gif'
  40.         nlMinus         : './js/tree/img/nolines_minus.gif' 
  41.     }; 
  42.     this.obj = objName; 
  43.     this.aNodes = []; 
  44.     this.aIndent = []; 
  45.     this.root = new Node(-1); 
  46.     this.selectedNode = null
  47.     this.selectedFound = false
  48.     this.completed = false
  49. }; 
  50.  

 

詳細參考:http://www.caohaifeng.com/code/javascript/dtree-api-2.html

 3.功能

add()
添加一個節點到樹形菜單裏,只有當樹形菜單加載完畢後纔可以執行此方法,id、pid、name不能爲空

  1. // Node object
  2.  
  3. //位置   參數別名     類型    功能 
  4. //1     id          int     節點自身的id(唯一) 
  5. //2     pid         int     節點的父節點id 
  6. //3     name        string  節點顯示在頁面上的名稱 
  7. //4     url         string  節點的鏈接地址 
  8. //5     title       string  鼠標放在節點上顯示的提示信息 
  9. //6     target      string  節點鏈接所打開的目標frame 
  10. //7     icon        string  節點關閉狀態時顯示的圖標 
  11. //8     iconOpen    string  節點打開狀態時顯示的圖標 
  12. //9     open        bool    節點第一次加載是否打開 
  13.  
  14. function Node(id, pid, name, url, title, target, icon, iconOpen, open)  

 

openall()
打開所有的節點,無論樹是否加載完畢都可以使用該方法

closeAll()
關閉所有的節點,無論樹是否加載完畢都可以使用該方法

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章