dojo中建立包含節點複選框的樹形(CheckBoxTree),dojocheckboxtree
樹形結構是介面設計程中常見的組件,在代碼實現時有很多方法,但由於設計到節點的父子關係和dom節點操作,實現起來比較複雜。dojo中提供了帶複選框的樹形組件CheckBoxTree,使用時只需建立對應的執行個體即可輕鬆實現此功能。
組件對應的html檔案代碼如下:
<div> <div dojoType="dijit.Dialog" dojoAttachPoint="testList" title="${title}" style="width: 100px;height:200px"> <div dojoType="dijit.layout.ContentPane" region="center" style="height:180px;"> <div dojoAttachPoint="testTree" style></div> </div> </div></div>
調用樹形組件的js檔案中需添加引用:
dojo.require("dojox.layout.ContentPane");dojo.require("tmpdir.CheckBoxTree");dojo.require("tmpdir.CheckBoxStoreModel");dojo.require("dojo.data.ItemFileWriteStore");
調用過程為:
var data = {identifier: "id",label: "name",items: content};//節點已id為唯一標示,name為節點顯示欄位//content為json對象,格式為[id:'id',name:'name',items:[]]var store = new dojo.data.ItemFileWriteStore({data: data});var model = new tmpdir.CheckBoxStoreModel({ store: store, childrenAttrs: ["items"], query: { id: '*' }});var tree = new tmpdir.CheckBoxTree({ model: model, showRoot: false,//是否顯示根節點 persist: false,// openOnClick : true,//點擊時是否開啟樹形 branchIcons : false,//父節點是否顯示圖形 nodeIcons: false,//子節點是否顯示圖形 autoExpand: true//載入後是否自動延伸}, this.testTree);