本篇內容主要講解“layui+java怎么實現樹形表格”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“layui+java怎么實現樹形表格”吧!
賓縣網站建設公司創新互聯,賓縣網站設計制作,有大型網站制作公司豐富經驗。已為賓縣數千家提供企業網站建設服務。企業網站搭建\成都外貿網站制作要多少錢,請找那個售后服務好的賓縣做網站的公司定做!
treeTable 模塊下載: https://gitee.com/whvse/treetable-lay/tree/master/2.x
下載后,treeTable.js、treeTable.css 的放置目錄分別為: layuiadmin/modules/treeTable.js layuiadmin/modules/treeTable/treeTable.css
頁面元素:
<div > <table class="layui-hide" id="businessConfigListTable" lay-filter="businessConfigListTable"></table> </div>
定義:
layui.config({ base: '${ctxLayui}/layuiadmin/' }).extend({ index: 'lib/index' }).use(['index', 'table','dict','laydate','util','treeTable'], function(){ var $ = layui.$,table = layui.table,form = layui.form; var dict = layui.dict; var laydate = layui.laydate; var admin = layui.admin; var util = layui.util; var treeTable = layui.treeTable;
渲染:
var insTb = treeTable.render({ elem: '#businessConfigListTable', tree: { iconIndex: 1, // 折疊圖標顯示在第幾列 idName: 'id', // 自定義id字段的名稱 pidName: 'parentId', // 自定義標識是否還有子節點的字段名稱 }, cols: [ {type: 'checkbox', fixed: 'left'}, {type: 'numbers',width: 120,style:'text-align:left'}, // {field: 'id', title: 'ID',width: 180}, {field: 'type', title: '類型', width: 120,templet:tplType}, {field: 'name', title: '名稱', width: 200}, {field: 'value', title: '值'}, {field: 'sortOrder', title: '排序', width: 120}, {field: 'status', title: '狀態', width: 150,templet:tplStatus}, {title:'操作', toolbar: '#businessConfigListTable-bar', width:120} ], reqData: function(data, callback) { // 在這里寫ajax請求,通過callback方法回調數據 var url = ctx+'/business/businessConfig/businessConfigTreeList'; var rtn = admin.syncReq(url,{}); var rtnData = rtn.data; for(var i=0;i<rtnData.length;i++){ var vo = rtnData[i]; vo.open = true; } callback(rtnData); } ,height: 'full-99' });
接口:business/businessConfig/businessConfigTreeList, 如下:
@RequestMapping(value = "businessConfigTreeList") @ResponseBody public BaseResp businessConfigTreeList(@ModelAttribute("command") BusinessConfigQo command){ BaseResp resp = new BaseResp(); try{ List<BusinessConfigPo> list = businessConfigService.businessConfigTreeList(command); resp.setData(list); }catch (Exception e){ error(logger,resp,e); } return resp; }
其中 BaseResp 結構:
/** * 應答返回碼 */ private int code = RC_OK; /** * 應答返回消息 */ private String msg; /** * 跳轉url */ private String url = ""; private int count; private boolean success = false;// 是否成功 private Object data;
service層獲取數據,遞歸:
public List<BusinessConfigPo> businessConfigTreeList(BusinessConfigQo command) throws Exception{ command.setParentId(0l); command.setLimit(99999); List<BusinessConfigPo> list = this.businessConfigMapper.query(command); for(BusinessConfigPo rec:list){ List<BusinessConfigPo> children = getChildrenConfig(rec); rec.setChildren(children); } return list; } private List<BusinessConfigPo> getChildrenConfig(BusinessConfigPo rec) throws Exception{ BusinessConfigQo qo = new BusinessConfigQo(); qo.setLimit(99999); qo.setParentId(rec.getId()); List<BusinessConfigPo> list = this.businessConfigMapper.query(qo); if(list==null){ return null; } for(BusinessConfigPo child:list){ List<BusinessConfigPo> children = getChildrenConfig(child); child.setChildren(children); } return list; }
到此,相信大家對“layui+java怎么實現樹形表格”有了更深的了解,不妨來實際操作一番吧!這里是創新互聯網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
當前題目:layui+java怎么實現樹形表格
分享網址:http://vcdvsql.cn/article46/gjseeg.html
成都網站建設公司_創新互聯,為您提供營銷型網站建設、網站策劃、網站設計、移動網站建設、小程序開發、動態網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯