本篇文章是接着Spring Boot 入门(五):集成 AOP 进行日志管理写的,主要集成了树形图,在部门列表或者权限列表中,树形图经常被用上。主要是根据相应的 API 凭借 html 字符串
1.treetable
1 <link href="/plugins/treeTable/themes/default/treeTable.css" rel="stylesheet" type="text/css" /> 2 <script src="/plugins/treeTable/jquery.treeTable.min.js" type="text/javascript"></script> 3 <script type="text/javascript"> 4 $(document).ready(function() {}); 5 </script> 6 7 <div class="row"> 8 <div class="col-xs-12"> 9 <div class="box"> 10 <div class="box-header with-border"> 11 <button type="button" class="close" data-dismiss="modal" aria-label="Close"> 12 <span aria-hidden="true">×</span> 13 </button> 14 <h3 class="box-title">选择部门</h3> 15 </div> 16 <div class="box-body"> 17 <table id="tcXzqh_tab" class="table table-striped table-bordered table-hover"> 18 <thead> 19 <tr> 20 <th>部门编号</th> 21 <th>部门名称</th> 22 <th>上级部门编号</th> 23 <th>上级部门名称</th> 24 </tr> 25 </thead> 26 <tbody> 27 </tbody> 28 </table> 29 </div> 30 </div> 31 </div> 32 </div> 33 34 <script> 35 var tcXzqh_tab; 36 function loadTcXzqhTable(){ 37 38 $.ajax({ 39 url: ‘/admin/dept/spage‘, 40 type: ‘post‘, 41 dataType: ‘json‘, 42 success: function (data) { 43 if(data !=null){ 44 var html = ""; 45 for (var int = 0; int < data.resultData.length; int++) { 46 var item = data.resultData[int]; 47 if(item.hasChild == true){ 48 html+= 49 "<tr id=‘"+item.xzqhbm+"‘ pId=‘"+item.pXzqhbm+"‘ haschild=‘true‘ ondblclick=_callback(‘" + item.xzqhbm + ":" + item.xzqh + "‘)>"; 50 }else{ 51 html+= 52 "<tr id=‘"+item.xzqhbm+"‘ pId=‘"+item.pXzqhbm+"‘ ondblclick=_callback(‘" + item.xzqhbm + ":" + item.xzqh + "‘)>"; 53 } 54 html+= 55 "<td nowrap>"+item.xzqhbm+"</td>"+ 56 "<td nowrap>"+item.xzqh+"</td>"+ 57 "<td nowrap>"+item.pXzqhbm+"</td>"+ 58 "<td nowrap>"+item.pXzqh +"</td>"+ 59 "</tr>"; 60 } 61 $("#tcXzqh_tab tbody").html(html); 62 initTcXzqh_treeTable(); 63 } 64 //$("#loading").hide(); 65 } 66 }); 67 } 68 function initTcXzqh_treeTable(){ 69 var option = { 70 /*theme:‘vsStyle‘,*//*这里的主题和引入的CSS有关*/ 71 expandLevel : 2, 72 beforeExpand : function($treeTable, id) { 73 //alert(id); 74 //判断id是否已经有了孩子节点,如果有了就不再加载,这样就可以起到缓存的作用 75 if ($(‘.‘ + id, $treeTable).length) { return; } 76 //这里的html可以是ajax请求 77 openHandleLoading(); 78 var childHtml=""; 79 $.ajax({ 80 url: ‘/admin/dept/expand?parentId=‘+id, 81 type: ‘post‘, 82 dataType: ‘json‘, 83 success: function (data) { 84 //alert(data); 85 if(data !=null){ 86 //var html = ""; 87 for (var int = 0; int < data.resultData.length; int++) { 88 var item = data.resultData[int]; 89 90 if(item.hasChild == true){ 91 childHtml+= 92 "<tr id=‘"+item.xzqhbm+"‘ pId=‘"+item.pXzqhbm+"‘ haschild=‘true‘ ondblclick=_callback(‘" + item.xzqhbm + ":" + item.xzqh + "‘)>"; 93 94 }else{ 95 childHtml+= 96 "<tr id=‘"+item.xzqhbm+"‘ pId=‘"+item.pXzqhbm+"‘ ondblclick=_callback(‘" + item.xzqhbm + ":" + item.xzqh + "‘)>"; 97 98 } 99 childHtml+= 100 "<td nowrap>"+item.xzqhbm+"</td>"+ 101 "<td nowrap>"+item.xzqh+"</td>"+ 102 "<td nowrap>"+item.pXzqhbm+"</td>"+ 103 "<td nowrap>"+item.pXzqh+"</td>"+ 104 "</tr>"; 105 } 106 107 } 108 $treeTable.addChilds(childHtml); 109 closeHandleLoading(); 110 } 111 }); 112 }, 113 onSelect : function($treeTable, id) { 114 //console.log(‘onSelect:‘ + id); 115 } 116 117 }; 118 119 $("#tcXzqh_tab").treeTable(option).show(); 120 //$("#tcXzqh_tab").treeTable({expandLevel : 2,column:0}).show(); 121 } 122 function _callback(chooseValue) { 123 /*alert(chooseValue);*/ 124 $("#${inputId!}").val(chooseValue); 125 $("#lgModal2").modal("hide"); 126 } 127 $(function () { 128 loadTcXzqhTable(); 129 }); 130 131 </script>
首先引入相应的 JS 文件和样式文件