tinguo002

 

树形全部展示代码

jsp:代码

<script type="text/javascript">

  $(function(){
   //alert('${tip}');
   if('${tip}'!=''){
    $('#tip').css('display','inline-block');
   }
  });
 
  var zTreeObj;
  var allSelectedId="";
  var allSelectedName = "";
  var zNodes = ${data};
  var setting = {
   isSimpleData: true,
   treeNodeKey: "id",         //设置节点唯一标识属性名称
   treeNodeParentKey: "pId",  //设置节点的父节点唯一标识属性名称
   nameCol: "name",           //设置 zTree 显示节点名称的属性名称,此处默认为Name
   showLine: true,            //在树型中是否显示线条样式
   
   check: {
    enable: true,
    chkStyle: "<%=type%>",
    chkboxType: <%=chkboxType%>,
    radioType: "all"
   },
   callback: {
    onClick: onClick
   },
   data: {
    simpleData: {
     enable: true
    }
   }
  };
   
  $(function(){
   $("#btnClose").bind("click",doClose);
   $("#btnConfirm").bind("click",doConfirm);
   zTreeObj = $("#tree").zTree(setting,zNodes);
  });
  
  //关闭窗口
  function doClose(){
   window.close();
  }
   
  function doConfirm(){
   var checkedNodes = zTreeObj.getCheckedNodes(true);
   alert(checkedNodes);
   for (i=0;i<checkedNodes.length;i++) {
   
    var treeNode = checkedNodes[i];
    alert(treeNode.id);
     if(!treeNode.open){
      allSelectedId += (allSelectedId == "" ? "" : ",") + treeNode.id;
      allSelectedName += (allSelectedName == "" ? "" : ",") + treeNode.name;      
     }
    }
   $('#hiddenId').val(allSelectedId);
   $('#hiddenName').val(allSelectedName);
  }
  
  function showMenu() {
   var deptname = $("#deptname");
   var offset = deptname.offset();
   $("#menu").width(deptname.width())
   .css({left:offset.left + "px", top:offset.top + deptname.outerHeight() + "px"})
   .slideDown("fast");
  }
  
  function hideMenu() {
   $("#menu").fadeOut("fast");
  }
  
  function onClick(e, treeId, treeNode) {
   alert(treeId);
   if(treeNode.checked){
    hideMenu();
   }else{
    zTreeObj.checkNode(treeNode, true, null, true);
   }
   return false;
  }
  
  function onCheck(e, treeId, treeNode){
   alert(treeNode.id);
   allSelectedId += (allSelectedId == "" ? "" : ",") + treeNode.pId+"|"+treeNode.id+"|"+treeNode.name;
  }
 </script>

java代码:

public class CameraTreeAPI {
 private static Logger log = Logger.getLogger(CameraTreeAPI.class);
 
 /**
  *
  * 功能说明:获取整个ztree摄像头树
  * @return  满足ztree要求的json数据
  * String
  * @author chh
  * @Jun 14, 2012
  */
 public  String getZTree(String systemUnid,String selectUnid){
  selectUnid = ","+StrUtil.formatNull(selectUnid)+",";
  JSONArray array = new JSONArray();
  try{
   List<BusinessCamera> list = new BusinessCameraManager().doFindBySystemUnid(systemUnid);
   
   JSONObject top = new JSONObject();
   top.put("id","0");
   top.put("name","摄像头列表");
   top.put("open",true);
   array.add(top);
   
   if(list!=null && list.size()>0){    
    for(Object object : list){
     BusinessCamera camera = (BusinessCamera)object;
     JSONObject json = new JSONObject();
     json.put("id",camera.getUnid());
     json.put("name",camera.getName());
     json.put("pId",camera.getPunid());
     json.put("checked", selectUnid.indexOf(camera.getUnid()) >= 0);
     if(hasChildren(list,camera)){
      json.put("open",true);
     }
     array.add(json);
    }
   }
  }catch(Exception e){
   e.printStackTrace();
   log.error(e.getMessage(),e);
  }
  return array.toString();
 }
 
 public boolean hasChildren(List<BusinessCamera> allData,BusinessCamera camera){
  if(allData == null || allData.isEmpty() || camera == null){
   return false;
  }
  for(BusinessCamera unit : allData){
   if(unit.getUnid().equalsIgnoreCase(camera.getUnid())){
    continue;
   }
   if(camera.getUnid().equalsIgnoreCase(unit.getPunid())){
    return true;
   }
  }
  return false;
 }
 
}




欢迎大家访问我的个人网站 萌萌的IT人

posted on 2013-12-30 19:16 一堣而安 阅读(223) 评论(0)  编辑  收藏 所属分类: java


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

收藏夹

搜索

最新评论

阅读排行榜

评论排行榜