tree.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. <a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=00000000000000" rel="nofollow">
  310. <img src="/public/upload/2021_8/168_1628847893037_87773.png" tppabs="http://cdn.layui.com/upload/2021_8/168_1628847893037_87773.png">
  311. 公网安备 00000000000000号
  312. </a>
  313. <a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">ICP备00000000号</a>
  314. </p>
  315. <div class="site-union">
  316. <p class="site-union-desc">
  317. <span>
  318. </span>
  319. </p>
  320. </div>
  321. </div>
  322. <script>
  323. window.global = {
  324. pageType: 'demo'
  325. ,preview: function(){
  326. var preview = document.getElementById('LAY_preview');
  327. return preview ? preview.innerHTML : '';
  328. }()
  329. };
  330. </script>
  331. <div class="site-tree-mobile layui-hide">
  332. <i class="layui-icon layui-icon-spread-left"></i>
  333. </div>
  334. <div class="site-mobile-shade"></div>
  335. <script src="/public/layui/dist/layui.js" tppabs="http://res.layui.com/layui/dist/layui.js?t=1632428048260" charset="utf-8"></script>
  336. <script>
  337. layui.config({
  338. base: '/public/static/lay/modules/layui/'
  339. ,version: '1632428048260'
  340. }).use('global');
  341. </script>
  342. </div>
  343. <div id="LAY_democodejs">
  344. <script>
  345. layui.use(['tree', 'util'], function(){
  346. var tree = layui.tree
  347. ,layer = layui.layer
  348. ,util = layui.util
  349. //模拟数据
  350. ,data = [{
  351. title: '一级1'
  352. ,id: 1
  353. ,field: 'name1'
  354. ,checked: true
  355. ,spread: true
  356. ,children: [{
  357. title: '二级1-1 可允许跳转'
  358. ,id: 3
  359. ,field: 'name11'
  360. ,href: 'https://www.layui.com/'
  361. ,children: [{
  362. title: '三级1-1-3'
  363. ,id: 23
  364. ,field: ''
  365. ,children: [{
  366. title: '四级1-1-3-1'
  367. ,id: 24
  368. ,field: ''
  369. ,children: [{
  370. title: '五级1-1-3-1-1'
  371. ,id: 30
  372. ,field: ''
  373. },{
  374. title: '五级1-1-3-1-2'
  375. ,id: 31
  376. ,field: ''
  377. }]
  378. }]
  379. },{
  380. title: '三级1-1-1'
  381. ,id: 7
  382. ,field: ''
  383. ,children: [{
  384. title: '四级1-1-1-1 可允许跳转'
  385. ,id: 15
  386. ,field: ''
  387. ,href: 'https://www.layui.com/doc/'
  388. }]
  389. },{
  390. title: '三级1-1-2'
  391. ,id: 8
  392. ,field: ''
  393. ,children: [{
  394. title: '四级1-1-2-1'
  395. ,id: 32
  396. ,field: ''
  397. }]
  398. }]
  399. },{
  400. title: '二级1-2'
  401. ,id: 4
  402. ,spread: true
  403. ,children: [{
  404. title: '三级1-2-1'
  405. ,id: 9
  406. ,field: ''
  407. ,disabled: true
  408. },{
  409. title: '三级1-2-2'
  410. ,id: 10
  411. ,field: ''
  412. }]
  413. },{
  414. title: '二级1-3'
  415. ,id: 20
  416. ,field: ''
  417. ,children: [{
  418. title: '三级1-3-1'
  419. ,id: 21
  420. ,field: ''
  421. },{
  422. title: '三级1-3-2'
  423. ,id: 22
  424. ,field: ''
  425. }]
  426. }]
  427. },{
  428. title: '一级2'
  429. ,id: 2
  430. ,field: ''
  431. ,spread: true
  432. ,children: [{
  433. title: '二级2-1'
  434. ,id: 5
  435. ,field: ''
  436. ,spread: true
  437. ,children: [{
  438. title: '三级2-1-1'
  439. ,id: 11
  440. ,field: ''
  441. },{
  442. title: '三级2-1-2'
  443. ,id: 12
  444. ,field: ''
  445. }]
  446. },{
  447. title: '二级2-2'
  448. ,id: 6
  449. ,field: ''
  450. ,children: [{
  451. title: '三级2-2-1'
  452. ,id: 13
  453. ,field: ''
  454. },{
  455. title: '三级2-2-2'
  456. ,id: 14
  457. ,field: ''
  458. ,disabled: true
  459. }]
  460. }]
  461. },{
  462. title: '一级3'
  463. ,id: 16
  464. ,field: ''
  465. ,children: [{
  466. title: '二级3-1'
  467. ,id: 17
  468. ,field: ''
  469. ,fixed: true
  470. ,children: [{
  471. title: '三级3-1-1'
  472. ,id: 18
  473. ,field: ''
  474. },{
  475. title: '三级3-1-2'
  476. ,id: 19
  477. ,field: ''
  478. }]
  479. },{
  480. title: '二级3-2'
  481. ,id: 27
  482. ,field: ''
  483. ,children: [{
  484. title: '三级3-2-1'
  485. ,id: 28
  486. ,field: ''
  487. },{
  488. title: '三级3-2-2'
  489. ,id: 29
  490. ,field: ''
  491. }]
  492. }]
  493. }]
  494. //模拟数据1
  495. ,data1 = [{
  496. title: '江西'
  497. ,id: 1
  498. ,children: [{
  499. title: '南昌'
  500. ,id: 1000
  501. ,children: [{
  502. title: '青山湖区'
  503. ,id: 10001
  504. },{
  505. title: '高新区'
  506. ,id: 10002
  507. }]
  508. },{
  509. title: '九江'
  510. ,id: 1001
  511. },{
  512. title: '赣州'
  513. ,id: 1002
  514. }]
  515. },{
  516. title: '广西'
  517. ,id: 2
  518. ,children: [{
  519. title: '南宁'
  520. ,id: 2000
  521. },{
  522. title: '桂林'
  523. ,id: 2001
  524. }]
  525. },{
  526. title: '陕西'
  527. ,id: 3
  528. ,children: [{
  529. title: '西安'
  530. ,id: 3000
  531. },{
  532. title: '延安'
  533. ,id: 3001
  534. }]
  535. }]
  536. //模拟数据2
  537. ,data2 = [{
  538. title: '早餐'
  539. ,id: 1
  540. ,children: [{
  541. title: '油条'
  542. ,id: 5
  543. },{
  544. title: '包子'
  545. ,id: 6
  546. },{
  547. title: '豆浆'
  548. ,id: 7
  549. }]
  550. },{
  551. title: '午餐'
  552. ,id: 2
  553. ,checked: true
  554. ,children: [{
  555. title: '藜蒿炒腊肉'
  556. ,id: 8
  557. },{
  558. title: '西湖醋鱼'
  559. ,id: 9
  560. },{
  561. title: '小白菜'
  562. ,id: 10
  563. },{
  564. title: '海带排骨汤'
  565. ,id: 11
  566. }]
  567. },{
  568. title: '晚餐'
  569. ,id: 3
  570. ,children: [{
  571. title: '红烧肉'
  572. ,id: 12
  573. ,fixed: true
  574. },{
  575. title: '番茄炒蛋'
  576. ,id: 13
  577. }]
  578. },{
  579. title: '夜宵'
  580. ,id: 4
  581. ,children: [{
  582. title: '小龙虾'
  583. ,id: 14
  584. ,checked: true
  585. },{
  586. title: '香辣蟹'
  587. ,id: 15
  588. ,disabled: true
  589. },{
  590. title: '烤鱿鱼'
  591. ,id: 16
  592. }]
  593. }];
  594. //基本演示
  595. tree.render({
  596. elem: '#test12'
  597. ,data: data
  598. ,showCheckbox: true //是否显示复选框
  599. ,id: 'demoId1'
  600. ,isJump: true //是否允许点击节点时弹出新窗口跳转
  601. ,click: function(obj){
  602. var data = obj.data; //获取当前点击的节点数据
  603. layer.msg('状态:'+ obj.state + '<br>节点数据:' + JSON.stringify(data));
  604. }
  605. });
  606. //按钮事件
  607. util.event('lay-demo', {
  608. getChecked: function(othis){
  609. var checkedData = tree.getChecked('demoId1'); //获取选中节点的数据
  610. layer.alert(JSON.stringify(checkedData), {shade:0});
  611. console.log(checkedData);
  612. }
  613. ,setChecked: function(){
  614. tree.setChecked('demoId1', [12, 16]); //勾选指定节点
  615. }
  616. ,reload: function(){
  617. //重载实例
  618. tree.reload('demoId1', {
  619. });
  620. }
  621. });
  622. //常规用法
  623. tree.render({
  624. elem: '#test1' //默认是点击节点可进行收缩
  625. ,data: data1
  626. });
  627. //无连接线风格
  628. tree.render({
  629. elem: '#test13'
  630. ,data: data1
  631. ,showLine: false //是否开启连接线
  632. });
  633. //仅节点左侧图标控制收缩
  634. tree.render({
  635. elem: '#test2'
  636. ,data: data1
  637. ,onlyIconControl: true //是否仅允许节点左侧图标控制展开收缩
  638. ,click: function(obj){
  639. layer.msg(JSON.stringify(obj.data));
  640. }
  641. });
  642. //手风琴模式
  643. tree.render({
  644. elem: '#test4'
  645. ,data: [{
  646. title: '优秀'
  647. ,children: [{
  648. title: '80 ~ 90'
  649. },{
  650. title: '90 ~ 100'
  651. }]
  652. },{
  653. title: '良好'
  654. ,children: [{
  655. title: '70 ~ 80'
  656. },{
  657. title: '60 ~ 70'
  658. }]
  659. },{
  660. title: '要努力奥'
  661. ,children: [{
  662. title: '0 ~ 60'
  663. }]
  664. }]
  665. ,accordion: true
  666. });
  667. //点击节点新窗口跳转
  668. tree.render({
  669. elem: '#test5'
  670. ,data: data
  671. ,isJump: true //link 为参数匹配
  672. });
  673. //开启复选框
  674. tree.render({
  675. elem: '#test7'
  676. ,data: data2
  677. ,showCheckbox: true
  678. });
  679. //开启节点操作图标
  680. tree.render({
  681. elem: '#test9'
  682. ,data: data1
  683. ,edit: ['add', 'update', 'del'] //操作节点的图标
  684. ,click: function(obj){
  685. layer.msg(JSON.stringify(obj.data));
  686. }
  687. });
  688. });
  689. </script>
  690. </div>
  691. </body>
  692. </html>