Tree 是 jQuery EasyUI 中用來呈現層級結構的元件。它可以直接使用 ul 元素定義,也可以透過遠端 JSON 資料動態載入。
若使用 ul 結構,只需將清單轉換為 tree 元件即可。若使用空容器,則可透過 url 指定資料來源,讓 Tree 自動載入節點。
每個節點通常可包含 id、text、state、checked、attributes 與 children。其中 state 可設為 open 或 closed,用來表示節點是否展開。
Tree 提供多種事件,例如 onClick、onDblClick、onBeforeLoad、onLoadSuccess、onLoadError、onBeforeExpand、onExpand、onBeforeCollapse、onCollapse、onCheck、onBeforeSelect、onSelect、onContextMenu、onDrop、onBeforeEdit、onAfterEdit 與 onCancelEdit。
常用方法包含 loadData、getNode、getData、reload、getRoot、getRoots、getParent、getChildren、getChecked、getSelected、find、select、check、uncheck、collapse、expand、collapseAll、expandAll、expandTo、append、toggle、insert、remove、pop、update、enableDnd、disableDnd、beginEdit、endEdit 與 cancelEdit。
Tree 適合處理分類、選單、檔案結構與層級資料。掌握節點資料格式與常用方法,就能快速建立互動式樹狀介面。