這篇文章主要為大家詳細介紹了Java easyui樹形表格TreeGrid的實現代碼,具有一定的參考價值,有興趣的小伙伴們可以參考一下
自己搞了一下午,終於用JAVA實現了資料網格。記錄一下實作的程式碼。 (PS:此處的easyui是1.5版本,樓主只貼了核心的程式碼)
實作圖
##JSP頁面
#
<head> //权限列表 $( document ).ready(function(){ var parentId = 0; $('#tt').treegrid({ url:'queryPrivilege.action?parentId='+parentId, idField:'id', treeField:'RecordStatus', columns:[[ {title:'id',field:'id',width:180}, {field:'RecordStatus',title:'RecordStatus',width:180} , {field:'PrivilegeOperation',title:'PrivilegeOperation',width:180} ]], onBeforeExpand:function(row){ //动态设置展开查询的url $(this).treegrid('options').url = 'queryPrivilege.action?parentId='+row.id; } }); }) </script> </head> <body> <table id="tt" style="width:600px;height:400px"></table> </body>ACTION層程式碼
//输出 public PrintWriter out()throws IOException{ HttpServletResponse response=ServletActionContext.getResponse(); response.setContentType("text/html"); response.setContentType("text/plain; charset=utf-8"); PrintWriter out= response.getWriter(); return out; } public String queryPrivilege() throws IOException{ returnpd="ok"; JSONArray array =new JSONArray(); array = privilegeService.getMenu(parentId); String str=array.toString(); out().print(str); out().flush(); out().close(); return returnpd; }Service層
介面程式碼
JSONArray getMenu(int parentId);ServiceImpl層程式碼(實作service層)
@Override public JSONArray getMenu(int parentId) { // TODO Auto-generated method stub return (JSONArray)privilegeDao.getMenu(parentId); }Dao層程式碼
JSONArray getMenu(int parentId);DaoImpl層程式碼(實作Dao層)
@Override public JSONArray getMenu(int parentId) { // TODO Auto-generated method stub String hql=""; JSONArray array=new JSONArray(); hql="FROM Privilege p WHERE p.parentID = "+parentId; for(Privilege privilege:(List<Privilege>)(getSession().createQuery(hql).list())){ JSONObject jo=new JSONObject(); jo.put("id", privilege.getId()); jo.put("RecordStatus", privilege.getRecordStatus()); jo.put("parendId",privilege.getParentID()); if(privilege.getParentID()==0){ jo.put("state","closed"); } else{ jo.put("state","open"); System.out.println(parentId); } array.add(jo); } return array; }資料庫一覽
##
以上是詳解Java easyui樹狀表格TreeGrid的範例程式碼(圖)的詳細內容。更多資訊請關注PHP中文網其他相關文章!