jquery 第三方控制元件ztree使用說明
阿新 • • 發佈:2018-11-02
1、引入相關資源
<link href="zTree/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
<script src="../javascript/jquery-1.7.1.min.js"></script>
<script src="zTree/jquery.ztree.core-3.5.min.js"></script>
2、設定頁面元素
<div class="zTreeDemoBackground left"> <ul id="treeDemo" class="ztree"></ul> </div>
主要是為一個ul的class 屬性設定一個 ztree
3、主要API
主要屬性:id表示當前元素編號
pId表示父級元素編號
name表示要顯示的文字
open表示是否展示,設定為true顯示展開
isParent表示沒有子級時,也顯示為父級圖示
url表示點選轉到的超連結
target表示在哪個視窗開啟超連結
click表示單擊事件的處理
4、主要demo
<script> var setting = { data: { simpleData: { enable: true } } }; var zNodes = [ { id: 1, pId: 0, name: "父節點1 - 展開", open: true }, { id: 11, pId: 1, name: "父節點11 - 摺疊" }, { id: 111, pId: 11, name: "葉子節點111" }, { id: 112, pId: 11, name: "葉子節點112" }, { id: 113, pId: 11, name: "葉子節點113" }, { id: 114, pId: 11, name: "葉子節點114" }, { id: 12, pId: 1, name: "父節點12 - 摺疊" }, { id: 121, pId: 12, name: "葉子節點121" }, { id: 122, pId: 12, name: "葉子節點122" }, { id: 123, pId: 12, name: "葉子節點123" }, { id: 124, pId: 12, name: "葉子節點124" }, { id: 13, pId: 1, name: "父節點13 - 沒有子節點", isParent: true }, { id: 2, pId: 0, name: "父節點2 - 摺疊" }, { id: 21, pId: 2, name: "父節點21 - 展開", open: true }, { id: 211, pId: 21, name: "葉子節點211" }, { id: 212, pId: 21, name: "葉子節點212" }, { id: 213, pId: 21, name: "葉子節點213" }, { id: 214, pId: 21, name: "葉子節點214" }, { id: 22, pId: 2, name: "父節點22 - 摺疊" }, { id: 221, pId: 22, name: "葉子節點221" }, { id: 222, pId: 22, name: "葉子節點222" }, { id: 223, pId: 22, name: "葉子節點223" }, { id: 224, pId: 22, name: "葉子節點224" }, { id: 23, pId: 2, name: "父節點23 - 摺疊" }, { id: 231, pId: 23, name: "葉子節點231" }, { id: 232, pId: 23, name: "葉子節點232" }, { id: 233, pId: 23, name: "葉子節點233" }, { id: 234, pId: 23, name: "葉子節點234" }, { id: 3, pId: 0, name: "父節點3 - 沒有子節點", isParent: true } ]; $.fn.zTree.init($("#treeDemo"), setting, zNodes); </script>
最後通過init方法把所有資料載入進去,傳入引數setting,(ztree設定) ,zNodes(資料)