index.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>TreeView-Lise</title>
  8. <link rel="stylesheet" href="./assets/bootstrap/css/bootstrap.css">
  9. <link rel="stylesheet" href="./assets/bootstrap-table.css">
  10. <script src="./assets/jquery.js"></script>
  11. <script src="./assets/bootstrap/js/bootstrap.js"></script>
  12. <script src="./assets/bootstrap-table.js"></script>
  13. <script src="./src/bootstraptable-treeview.js"></script>
  14. </head>
  15. <body>
  16. <div style="margin:20px">
  17. <input type="button" id="expandAllTree" value="展开所有" class="btn btn-defaul"/>
  18. <input type="button" id="collapseAllTree" value="折叠所有" class="btn btn-defaul"/>
  19. <table id="tree_table"></table>
  20. </div>
  21. <script>
  22. $(function () {
  23. var data = [
  24. {
  25. id: '1',
  26. name: "aa",
  27. desc: "这是一个描述",
  28. parentId:null,
  29. },{
  30. id: '11',
  31. name: "aa_sub1",
  32. desc: "这是一个描述_sub1",
  33. parentId:'1',
  34. },{
  35. id: '111',
  36. name: "aa_sub1_sub2",
  37. desc: "这是一个描述_sub1_sub2" ,
  38. parentId:'11',
  39. },
  40. {
  41. id: '2',
  42. name: "bb",
  43. desc: "这是一个描述",
  44. parentId:null,
  45. },
  46. {
  47. id: '22',
  48. name: "bb_sub1",
  49. desc: "这是一个描述_sub1",
  50. parentId:'2',
  51. },{
  52. id: '23',
  53. name: "bb_sub2",
  54. desc: "这是一个描述_sub2",
  55. parentId:'2',
  56. },{
  57. id: '233',
  58. name: "bb_sub2_sub2",
  59. desc: "这是一个描述_sub2_sub2",
  60. parentId:'23',
  61. },{
  62. id: '2333',
  63. name: "bb_sub2_sub2_sub2",
  64. desc: "这是一个描述_sub2_sub2_sub2",
  65. parentId:'233',
  66. },{
  67. id: '23333',
  68. name: "bb_sub2_sub2_sub23",
  69. desc: "这是一个描述_sub2_sub2_sub2",
  70. parentId:'233',
  71. },{
  72. id: '233333',
  73. name: "bb_sub2_sub2_sub233",
  74. desc: "这是一个描述_sub2_sub2_sub2",
  75. parentId:'233',
  76. },{
  77. id: '24',
  78. name: "bb_sub3",
  79. desc: "这是一个描述_sub3",
  80. parentId:'2',
  81. },
  82. ]
  83. $('#tree_table').bootstrapTable({
  84. class: 'table table-hover table-bordered',
  85. // url:'data.json',
  86. // contentType: 'application/x-www-form-urlencoded; charset=utf-8',
  87. data: data,
  88. sidePagination: 'server',
  89. pagination: false,
  90. treeView: true,
  91. treeId: "id",
  92. treeField: "name",
  93. rowAttributes: function (row, index) {
  94. return {
  95. xx:index
  96. };
  97. },
  98. columns: [{
  99. checkbox:true
  100. },{
  101. field: 'name',
  102. title: '名称',
  103. },
  104. {
  105. field: 'desc',
  106. title: '详情',
  107. },
  108. ]
  109. });
  110. $("#expandAllTree").on('click',function(){
  111. $('#tree_table').bootstrapTable("expandAllTree")
  112. })
  113. $("#collapseAllTree").on('click',function(){
  114. $('#tree_table').bootstrapTable("collapseAllTree")
  115. })
  116. });
  117. </script>
  118. </body>
  119. </html>