codecamp

Java easyui树形表格TreeGrid的实现代码

自己搞了一下午,终于用JAVA实现了数据网格。记录一下实现的代码。(PS:此处的easyui是1.5版本,楼主只贴了核心的代码)

实现图

JSP页面

<head>
<script type="text/javascript">
//权限列表
$( 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> 

java代码

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层接口代码

public abstract JSONArray getMenu(int parentId);

ServiceImpl层代码(实现service层)

@Override
  public JSONArray getMenu(int parentId) {
    // TODO Auto-generated method stub
    return (JSONArray)privilegeDao.getMenu(parentId);
  }

Dao层代码接口代码

public abstract 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;
}

数据库一览

转载地址:http://www.jb51.net/article/108687.htm

Ajax
easyui中文解析
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Ueditor

My97 DatePicker

Dtree——Js树型控件

浏览系

无标题目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }