tree.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>镜像站@ 树形组件- 在线演示 - Layui</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  9. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  10. <meta name="apple-mobile-web-app-capable" content="yes">
  11. <meta name="format-detection" content="telephone=no">
  12. <script>
  13. ;!function(){self!==parent&&(location.href="http://www.baidu.com/")}();
  14. </script>
  15. <link rel="stylesheet" href="/public/layui/dist/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css?t=1632428048260" media="all">
  16. <link rel="stylesheet" href="/public/static/css/global.css" tppabs="http://res.layui.com/static/css/global.css?t=1632428048260-19" media="all">
  17. <style>
  18. .demo-tree{margin: 10px 20px;}
  19. .demo-tree-more{margin: 20px;}
  20. .demo-tree-box{width: 200px; padding: 10px; border: 1px solid #ddd; overflow: auto;}
  21. </style>
  22. </head>
  23. <body>
  24. <div class="layui-layout layui-layout-admin">
  25. <div class="layui-header header header-demo" autumn>
  26. <div class="layui-fluid">
  27. <a class="logo" href="../index.html" tppabs="http://www.layui.com/">
  28. <img src="/public/static/images/layui/logo.png" tppabs="http://res.layui.com/static/images/layui/logo.png" alt="layui">
  29. </a>
  30. <div class="layui-form layui-hide-xs component" lay-filter="LAY-site-header-component"></div>
  31. <div class="layui-hide-xs site-notice"></div>
  32. <ul class="layui-nav" id="LAY_NAV_TOP">
  33. <li class="layui-nav-item ">
  34. <a href="../doc/index.html" tppabs="http://www.layui.com/doc/">文档</a>
  35. </li>
  36. <li class="layui-nav-item layui-this">
  37. <a href="index.html" tppabs="http://www.layui.com/demo/">示例</a>
  38. </li>
  39. <li class="layui-nav-item">
  40. <a href="javascript:;">
  41. <!--<span class="layui-badge-dot" style="left:0; right: auto; margin: -4px 0 0 5px;"></span>-->
  42. 周边
  43. </a>
  44. <dl class="layui-nav-child layui-nav-child-c">
  45. <dd class="layui-hide-sm layui-show-xs" lay-unselect>
  46. <a href="https://gitee.com/sentsin/layui/issues" target="_blank" rel="nofollow">问题反馈</a>
  47. <hr>
  48. </dd>
  49. <dd lay-unselect><a href="../alone.html" tppabs="http://www.layui.com/alone.html" target="_blank" lay-unselect>独立组件</a></dd>
  50. <dd lay-unselect><a href="../../fly.layui.com/extend/index.html" target="_blank">扩展组件</a></dd>
  51. </dl>
  52. </li>
  53. <li class="layui-nav-item layui-hide-xs">
  54. <a href="http://gitee.com/sentsin/layui/issues" target="_blank" rel="nofollow">反馈</a>
  55. </li>
  56. </ul>
  57. </div>
  58. </div>
  59. <!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
  60. <!--[if lt IE 9]>
  61. <script src="../../other/html5shiv/r29/html5.min.js" tppabs="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  62. <script src="../../other/respond.js/1.4.2/respond.min.js" tppabs="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  63. <![endif]-->
  64. <div class="layui-side layui-bg-black">
  65. <div class="layui-side-scroll">
  66. <ul class="layui-nav layui-nav-tree site-demo-nav">
  67. <li class="layui-nav-item layui-nav-itemed">
  68. <a class="javascript:;" href="javascript:;">演示</a>
  69. <dl class="layui-nav-child">
  70. <dd>
  71. <a href="index.html" tppabs="http://www.layui.com/demo/">调试预览</a>
  72. </dd>
  73. </dl>
  74. </li>
  75. <li class="layui-nav-item layui-nav-itemed">
  76. <a class="javascript:;" href="javascript:;">布局</a>
  77. <dl class="layui-nav-child">
  78. <dd class="">
  79. <a href="grid.html" tppabs="http://www.layui.com/demo/grid.html">栅格</a>
  80. </dd>
  81. <dd class="">
  82. <a href="admin.html" tppabs="http://www.layui.com/demo/admin.html">框架</a>
  83. </dd>
  84. </dl>
  85. </li>
  86. <li class="layui-nav-item layui-nav-itemed">
  87. <a class="javascript:;" href="javascript:;">基本元素</a>
  88. <dl class="layui-nav-child">
  89. <dd class="">
  90. <a href="button.html" tppabs="http://www.layui.com/demo/button.html">按钮</a>
  91. </dd>
  92. <dd class="">
  93. <a href="form.html" tppabs="http://www.layui.com/demo/form.html">表单</a>
  94. </dd>
  95. <dd class="">
  96. <a href="nav.html" tppabs="http://www.layui.com/demo/nav.html">导航 / 面包屑</a>
  97. </dd>
  98. <dd class="">
  99. <a href="menu.html" tppabs="http://www.layui.com/demo/menu.html">基础菜单</a>
  100. </dd>
  101. <dd class="">
  102. <a href="tab.html" tppabs="http://www.layui.com/demo/tab.html">选项卡</a>
  103. </dd>
  104. <dd class="">
  105. <a href="progress.html" tppabs="http://www.layui.com/demo/progress.html">进度条</a>
  106. </dd>
  107. <dd class="">
  108. <a href="panel.html" tppabs="http://www.layui.com/demo/panel.html">面板</a>
  109. </dd>
  110. <dd class="">
  111. <a href="badge.html" tppabs="http://www.layui.com/demo/badge.html">徽章</a>
  112. </dd>
  113. <dd class="">
  114. <a href="timeline.html" tppabs="http://www.layui.com/demo/timeline.html">时间线</a>
  115. </dd>
  116. <dd class="">
  117. <a href="table-element.html" tppabs="http://www.layui.com/demo/table-element.html">静态表格</a>
  118. </dd>
  119. <dd class="">
  120. <a href="anim.html" tppabs="http://www.layui.com/demo/anim.html">动画</a>
  121. </dd>
  122. <dd class="">
  123. <a href="auxiliar.html" tppabs="http://www.layui.com/demo/auxiliar.html">辅助元素</a>
  124. </dd>
  125. </dl>
  126. </li>
  127. <li class="layui-nav-item layui-nav-itemed">
  128. <a class="javascript:;" href="javascript:;">组件示例</a>
  129. <dl class="layui-nav-child">
  130. <dd class="">
  131. <a href="layer.html" tppabs="http://www.layui.com/demo/layer.html">
  132. 弹出层
  133. </a>
  134. </dd>
  135. <dd class="">
  136. <a href="laydate.html" tppabs="http://www.layui.com/demo/laydate.html">
  137. 日期与时间选择
  138. </a>
  139. </dd>
  140. <dd class="">
  141. <a href="table.html" tppabs="http://www.layui.com/demo/table.html">
  142. 数据表格
  143. </a>
  144. </dd>
  145. <dd class="">
  146. <a href="laypage.html" tppabs="http://www.layui.com/demo/laypage.html">
  147. 分页
  148. </a>
  149. </dd>
  150. <dd class="">
  151. <a href="dropdown.html" tppabs="http://www.layui.com/demo/dropdown.html">
  152. 下拉菜单
  153. </a>
  154. </dd>
  155. <dd class="">
  156. <a href="upload.html" tppabs="http://www.layui.com/demo/upload.html">
  157. 文件上传
  158. </a>
  159. </dd>
  160. <dd class="">
  161. <a href="transfer.html" tppabs="http://www.layui.com/demo/transfer.html">
  162. 穿梭框
  163. </a>
  164. </dd>
  165. <dd class="layui-this">
  166. <a href="tree.html" tppabs="http://www.layui.com/demo/tree.html">
  167. 树形组件
  168. </a>
  169. </dd>
  170. <dd class="">
  171. <a href="colorpicker.html" tppabs="http://www.layui.com/demo/colorpicker.html">
  172. 颜色选择器
  173. </a>
  174. </dd>
  175. <dd class="">
  176. <a href="slider.html" tppabs="http://www.layui.com/demo/slider.html">
  177. 滑块
  178. </a>
  179. </dd>
  180. <dd class="">
  181. <a href="rate.html" tppabs="http://www.layui.com/demo/rate.html">
  182. 评分
  183. </a>
  184. </dd>
  185. <dd class="">
  186. <a href="carousel.html" tppabs="http://www.layui.com/demo/carousel.html">
  187. 轮播
  188. </a>
  189. </dd>
  190. <dd class="">
  191. <a href="laytpl.html" tppabs="http://www.layui.com/demo/laytpl.html">
  192. 模板引擎
  193. </a>
  194. </dd>
  195. <dd class="">
  196. <a href="layedit.html" tppabs="http://www.layui.com/demo/layedit.html">
  197. 富文本编辑器
  198. </a>
  199. </dd>
  200. <dd class="">
  201. <a href="flow.html" tppabs="http://www.layui.com/demo/flow.html">
  202. 流加载
  203. </a>
  204. </dd>
  205. <dd class="">
  206. <a href="util.html" tppabs="http://www.layui.com/demo/util.html">
  207. 工具模块
  208. </a>
  209. </dd>
  210. <dd class="">
  211. <a href="code.html" tppabs="http://www.layui.com/demo/code.html">
  212. 文本行修饰
  213. </a>
  214. </dd>
  215. </dl>
  216. </li>
  217. <li class="layui-nav-item" style="height: 30px; text-align: center"></li>
  218. </ul>
  219. </div>
  220. </div>
  221. <div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
  222. <ul class="layui-tab-title site-demo-title">
  223. <li class="layui-this">预览</li>
  224. <li>查看代码</li>
  225. <li>帮助</li>
  226. </ul>
  227. <div class="layui-body layui-tab-content site-demo site-demo-body">
  228. <div class="layui-tab-item layui-show">
  229. <div class="layui-main">
  230. <div id="LAY_preview">
  231. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  232. <legend>基本演示</legend>
  233. </fieldset>
  234. <div class="layui-btn-container">
  235. <button type="button" class="layui-btn layui-btn-sm" lay-demo="getChecked">获取选中节点数据</button>
  236. <button type="button" class="layui-btn layui-btn-sm" lay-demo="setChecked">勾选指定节点</button>
  237. <button type="button" class="layui-btn layui-btn-sm" lay-demo="reload">重载实例</button>
  238. </div>
  239. <div id="test12" class="demo-tree-more"></div>
  240. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  241. <legend>常规用法</legend>
  242. </fieldset>
  243. <div id="test1" class="demo-tree demo-tree-box"></div>
  244. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  245. <legend>无连接线风格</legend>
  246. </fieldset>
  247. <div id="test13" class="demo-tree-more"></div>
  248. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  249. <legend>仅节点左侧图标控制收缩</legend>
  250. </fieldset>
  251. <div id="test2" class="demo-tree"></div>
  252. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  253. <legend>手风琴模式</legend>
  254. </fieldset>
  255. <div id="test4" class="demo-tree"></div>
  256. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  257. <legend>点击节点新窗口跳转</legend>
  258. </fieldset>
  259. <div id="test5" class="demo-tree"></div>
  260. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  261. <legend>开启复选框</legend>
  262. </fieldset>
  263. <div id="test7" class="demo-tree"></div>
  264. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  265. <legend>开启节点操作图标</legend>
  266. </fieldset>
  267. <div id="test9" class="demo-tree demo-tree-box" style="width: 200px; height: 300px; overflow: scroll;"></div>
  268. </div>
  269. <blockquote class="layui-elem-quote" style="margin-top: 30px;">
  270. 更多我们未能呈现的示例,还有待您在阅读文档、以及不断使用的过程,去深入挖掘。
  271. </blockquote>
  272. <div style="margin: 15px 0 100px; padding-bottom: 100px;">
  273. </div>
  274. </div>
  275. </div>
  276. <div class="layui-tab-item">
  277. <textarea class="layui-border-box site-demo-text site-demo-code" id="LAY_democode" spellcheck="false" readonly>
  278. <!DOCTYPE html>
  279. <html>
  280. <head>
  281. <meta charset="utf-8">
  282. <title>镜像站@Layui</title>
  283. <meta name="renderer" content="webkit">
  284. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  285. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  286. <link rel="stylesheet" href="/public/layui/dist/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css" media="all">
  287. <!-- 注意:如果你直接复制所有代码到本地,上述css路径需要改成你本地的 -->
  288. </head>
  289. </textarea>
  290. </div>
  291. <div class="layui-tab-item">
  292. <div class="layui-main">
  293. <p></p>
  294. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  295. <legend>相关</legend>
  296. </fieldset>
  297. <a class="layui-btn layui-btn-normal" href="../doc/modules/tree.html" tppabs="http://www.layui.com/doc/modules/tree.html" target="_blank">树形组件文档</a>
  298. </div>
  299. </div>
  300. </div>
  301. </div>
  302. <div class="layui-footer footer footer-demo">
  303. <p>
  304. Copyright &copy; 2021 <a href="../index.html" tppabs="http://www.layui.com/">「本站仅为 layui 文档保留的镜像站点,与官方无关」</a> MIT Licensed</p>
  305. <p>
  306. <a href="../about/disclaimer.html" tppabs="http://www.layui.com/about/disclaimer.html" target="_blank">免责声明</a>
  307. <a href="../about/relatedlinks.html" tppabs="http://www.layui.com/about/relatedlinks.html" target="_blank">友链</a>
  308. <a href="javascript:;" site-event="weixinmp">公众号</a>
  309. </p>
  310. <div class="site-union">
  311. <p class="site-union-desc">
  312. <span>
  313. </span>
  314. </p>
  315. </div>
  316. </div>
  317. <script>
  318. window.global = {
  319. pageType: 'demo'
  320. ,preview: function(){
  321. var preview = document.getElementById('LAY_preview');
  322. return preview ? preview.innerHTML : '';
  323. }()
  324. };
  325. </script>
  326. <div class="site-tree-mobile layui-hide">
  327. <i class="layui-icon layui-icon-spread-left"></i>
  328. </div>
  329. <div class="site-mobile-shade"></div>
  330. <script src="/public/layui/dist/layui.js" tppabs="http://res.layui.com/layui/dist/layui.js?t=1632428048260" charset="utf-8"></script>
  331. <script>
  332. layui.config({
  333. base: '/public/static/lay/modules/layui/'
  334. ,version: '1632428048260'
  335. }).use('global');
  336. </script>
  337. </div>
  338. <div id="LAY_democodejs">
  339. <script>
  340. layui.use(['tree', 'util'], function(){
  341. var tree = layui.tree
  342. ,layer = layui.layer
  343. ,util = layui.util
  344. //模拟数据
  345. ,data = [{
  346. title: '一级1'
  347. ,id: 1
  348. ,field: 'name1'
  349. ,checked: true
  350. ,spread: true
  351. ,children: [{
  352. title: '二级1-1 可允许跳转'
  353. ,id: 3
  354. ,field: 'name11'
  355. ,href: 'https://www.layui.com/'
  356. ,children: [{
  357. title: '三级1-1-3'
  358. ,id: 23
  359. ,field: ''
  360. ,children: [{
  361. title: '四级1-1-3-1'
  362. ,id: 24
  363. ,field: ''
  364. ,children: [{
  365. title: '五级1-1-3-1-1'
  366. ,id: 30
  367. ,field: ''
  368. },{
  369. title: '五级1-1-3-1-2'
  370. ,id: 31
  371. ,field: ''
  372. }]
  373. }]
  374. },{
  375. title: '三级1-1-1'
  376. ,id: 7
  377. ,field: ''
  378. ,children: [{
  379. title: '四级1-1-1-1 可允许跳转'
  380. ,id: 15
  381. ,field: ''
  382. ,href: 'https://www.layui.com/doc/'
  383. }]
  384. },{
  385. title: '三级1-1-2'
  386. ,id: 8
  387. ,field: ''
  388. ,children: [{
  389. title: '四级1-1-2-1'
  390. ,id: 32
  391. ,field: ''
  392. }]
  393. }]
  394. },{
  395. title: '二级1-2'
  396. ,id: 4
  397. ,spread: true
  398. ,children: [{
  399. title: '三级1-2-1'
  400. ,id: 9
  401. ,field: ''
  402. ,disabled: true
  403. },{
  404. title: '三级1-2-2'
  405. ,id: 10
  406. ,field: ''
  407. }]
  408. },{
  409. title: '二级1-3'
  410. ,id: 20
  411. ,field: ''
  412. ,children: [{
  413. title: '三级1-3-1'
  414. ,id: 21
  415. ,field: ''
  416. },{
  417. title: '三级1-3-2'
  418. ,id: 22
  419. ,field: ''
  420. }]
  421. }]
  422. },{
  423. title: '一级2'
  424. ,id: 2
  425. ,field: ''
  426. ,spread: true
  427. ,children: [{
  428. title: '二级2-1'
  429. ,id: 5
  430. ,field: ''
  431. ,spread: true
  432. ,children: [{
  433. title: '三级2-1-1'
  434. ,id: 11
  435. ,field: ''
  436. },{
  437. title: '三级2-1-2'
  438. ,id: 12
  439. ,field: ''
  440. }]
  441. },{
  442. title: '二级2-2'
  443. ,id: 6
  444. ,field: ''
  445. ,children: [{
  446. title: '三级2-2-1'
  447. ,id: 13
  448. ,field: ''
  449. },{
  450. title: '三级2-2-2'
  451. ,id: 14
  452. ,field: ''
  453. ,disabled: true
  454. }]
  455. }]
  456. },{
  457. title: '一级3'
  458. ,id: 16
  459. ,field: ''
  460. ,children: [{
  461. title: '二级3-1'
  462. ,id: 17
  463. ,field: ''
  464. ,fixed: true
  465. ,children: [{
  466. title: '三级3-1-1'
  467. ,id: 18
  468. ,field: ''
  469. },{
  470. title: '三级3-1-2'
  471. ,id: 19
  472. ,field: ''
  473. }]
  474. },{
  475. title: '二级3-2'
  476. ,id: 27
  477. ,field: ''
  478. ,children: [{
  479. title: '三级3-2-1'
  480. ,id: 28
  481. ,field: ''
  482. },{
  483. title: '三级3-2-2'
  484. ,id: 29
  485. ,field: ''
  486. }]
  487. }]
  488. }]
  489. //模拟数据1
  490. ,data1 = [{
  491. title: '江西'
  492. ,id: 1
  493. ,children: [{
  494. title: '南昌'
  495. ,id: 1000
  496. ,children: [{
  497. title: '青山湖区'
  498. ,id: 10001
  499. },{
  500. title: '高新区'
  501. ,id: 10002
  502. }]
  503. },{
  504. title: '九江'
  505. ,id: 1001
  506. },{
  507. title: '赣州'
  508. ,id: 1002
  509. }]
  510. },{
  511. title: '广西'
  512. ,id: 2
  513. ,children: [{
  514. title: '南宁'
  515. ,id: 2000
  516. },{
  517. title: '桂林'
  518. ,id: 2001
  519. }]
  520. },{
  521. title: '陕西'
  522. ,id: 3
  523. ,children: [{
  524. title: '西安'
  525. ,id: 3000
  526. },{
  527. title: '延安'
  528. ,id: 3001
  529. }]
  530. }]
  531. //模拟数据2
  532. ,data2 = [{
  533. title: '早餐'
  534. ,id: 1
  535. ,children: [{
  536. title: '油条'
  537. ,id: 5
  538. },{
  539. title: '包子'
  540. ,id: 6
  541. },{
  542. title: '豆浆'
  543. ,id: 7
  544. }]
  545. },{
  546. title: '午餐'
  547. ,id: 2
  548. ,checked: true
  549. ,children: [{
  550. title: '藜蒿炒腊肉'
  551. ,id: 8
  552. },{
  553. title: '西湖醋鱼'
  554. ,id: 9
  555. },{
  556. title: '小白菜'
  557. ,id: 10
  558. },{
  559. title: '海带排骨汤'
  560. ,id: 11
  561. }]
  562. },{
  563. title: '晚餐'
  564. ,id: 3
  565. ,children: [{
  566. title: '红烧肉'
  567. ,id: 12
  568. ,fixed: true
  569. },{
  570. title: '番茄炒蛋'
  571. ,id: 13
  572. }]
  573. },{
  574. title: '夜宵'
  575. ,id: 4
  576. ,children: [{
  577. title: '小龙虾'
  578. ,id: 14
  579. ,checked: true
  580. },{
  581. title: '香辣蟹'
  582. ,id: 15
  583. ,disabled: true
  584. },{
  585. title: '烤鱿鱼'
  586. ,id: 16
  587. }]
  588. }];
  589. //基本演示
  590. tree.render({
  591. elem: '#test12'
  592. ,data: data
  593. ,showCheckbox: true //是否显示复选框
  594. ,id: 'demoId1'
  595. ,isJump: true //是否允许点击节点时弹出新窗口跳转
  596. ,click: function(obj){
  597. var data = obj.data; //获取当前点击的节点数据
  598. layer.msg('状态:'+ obj.state + '<br>节点数据:' + JSON.stringify(data));
  599. }
  600. });
  601. //按钮事件
  602. util.event('lay-demo', {
  603. getChecked: function(othis){
  604. var checkedData = tree.getChecked('demoId1'); //获取选中节点的数据
  605. layer.alert(JSON.stringify(checkedData), {shade:0});
  606. console.log(checkedData);
  607. }
  608. ,setChecked: function(){
  609. tree.setChecked('demoId1', [12, 16]); //勾选指定节点
  610. }
  611. ,reload: function(){
  612. //重载实例
  613. tree.reload('demoId1', {
  614. });
  615. }
  616. });
  617. //常规用法
  618. tree.render({
  619. elem: '#test1' //默认是点击节点可进行收缩
  620. ,data: data1
  621. });
  622. //无连接线风格
  623. tree.render({
  624. elem: '#test13'
  625. ,data: data1
  626. ,showLine: false //是否开启连接线
  627. });
  628. //仅节点左侧图标控制收缩
  629. tree.render({
  630. elem: '#test2'
  631. ,data: data1
  632. ,onlyIconControl: true //是否仅允许节点左侧图标控制展开收缩
  633. ,click: function(obj){
  634. layer.msg(JSON.stringify(obj.data));
  635. }
  636. });
  637. //手风琴模式
  638. tree.render({
  639. elem: '#test4'
  640. ,data: [{
  641. title: '优秀'
  642. ,children: [{
  643. title: '80 ~ 90'
  644. },{
  645. title: '90 ~ 100'
  646. }]
  647. },{
  648. title: '良好'
  649. ,children: [{
  650. title: '70 ~ 80'
  651. },{
  652. title: '60 ~ 70'
  653. }]
  654. },{
  655. title: '要努力奥'
  656. ,children: [{
  657. title: '0 ~ 60'
  658. }]
  659. }]
  660. ,accordion: true
  661. });
  662. //点击节点新窗口跳转
  663. tree.render({
  664. elem: '#test5'
  665. ,data: data
  666. ,isJump: true //link 为参数匹配
  667. });
  668. //开启复选框
  669. tree.render({
  670. elem: '#test7'
  671. ,data: data2
  672. ,showCheckbox: true
  673. });
  674. //开启节点操作图标
  675. tree.render({
  676. elem: '#test9'
  677. ,data: data1
  678. ,edit: ['add', 'update', 'del'] //操作节点的图标
  679. ,click: function(obj){
  680. layer.msg(JSON.stringify(obj.data));
  681. }
  682. });
  683. });
  684. </script>
  685. </div>
  686. </body>
  687. </html>