您好,登錄后才能下訂單哦!
本篇內容主要講解“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怎么實現樹形表格”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。