从后台传一个id,如何使ztree显示的时候选中某个节点,求指导,谢谢。

yuan_bin1990 发布于 2012/12/21 11:01
阅读 3K+
收藏 0

我从后台从一个id,如何加载ztree树的时候,使这个id的节点为选中状态,代码如下,求指导,谢谢。

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>知识分类树</title>
 <link rel="stylesheet" href="css/zTreeStyle/zTreeStyle.css" type="text/css">
 <script type="text/javascript" src="js/jquery.js"></script>
 <script type="text/javascript" src="js/jquery.ztree.core-3.1.js"></script>
 <script type="text/javascript" src="js/jquery.ztree.excheck-3.1.js"></script>
 <script type="text/javascript">
 var setting = {
   view: {
    selectedMulti: false
   },
   check: {
    enable: true
   },
   async: {
              enable:true,
              dataType:"json",
               type:"post",
               url:"depttree.do"
            },
   
   data: {
    simpleData: {
     enable: true,
     idKey:"id",
     pidKey:"pId"
    }
   },
   callback: {
    onCheck: onCheck
   }
  };
 
   function onCheck(e,treeId,treeNode){
    alert(treeNode.id+"------"+treeNode.name);
   }
  //var zNodes =[
  // { id:1, pId:0, name:"父节点1 - 展开"},
  // { id:11, pId:1, name:"父节点11 - 折叠"},
     // { id:111, pId:11, name:"叶子节点111"},
  // { id:112, pId:11, name:"叶子节点112"},
  // { id:113, pId:11, name:"叶子节点113"},
  // { id:114, pId:11, name:"叶子节点114"},
  // { id:12, pId:1, name:"父节点12 - 折叠"},
  // { id:121, pId:12, name:"叶子节点121"},
  // { id:122, pId:12, name:"叶子节点122"},
  // { id:123, pId:12, name:"叶子节点123"},
  // { id:124, pId:12, name:"叶子节点124"},
  // { id:13, pId:1, name:"父节点13 - 没有子节点"}
  //];
 
  $(document).ready(function(){
   $.fn.zTree.init($("#treeDemo"), setting);
   var ztree=$.fn.zTree.getZTreeObj("tree");
   ztree.selectNode(ztree.getNodeByParam("id",3, null));
  });
  
  
  function returnStr(){
   returnValue = $("#dicids").val()+";"+$("#checkDic").val();
   window.close();
  }
  function returnClear(){
   tree.resetIds();
   tree.isReset=true;
   $("#dicids").attr("value","");
   $("#checkDic").attr("value","");
  }
 </script>
</head>
<body>
<div id="showDic">
</div>
<div id="divCheckValue" style="widows: inherit">
 <div class="zTreeDemoBackground left" id="tree">
  <ul id="treeDemo" class="ztree"></ul>
 </div>
 <div>您选择的部门是:<br />       
  <div align="center">
   <textarea cols="15" rows="8" id="checkDic" style="height:60px;width:255px; font-size:12" readonly="readonly">${parentName}</textarea><input type="hidden" name="dicids" id="dicids" value="${parentid }"/>
  </div>
 </div>
 <div align="center">
     <input type="button" value="确 定" onclick="returnStr();" class="BtnStyle" />&nbsp;
     <input type="button" value="重 置" onclick="returnClear();" class="BtnStyle empty" />&nbsp;
    </div>
</div>
</body>
</html>

 

加载中
返回顶部
顶部