dtree中new dTree('d')报d is not defined

妞妞超人 发布于 2013/07/24 11:22
阅读 816
收藏 0

在主页面的左侧加载部门信息

<div style="width: 27%;float: left;height: auto;">
              <iframe name="depTree" src="${pageContext.request.contextPath }/info/SysUserPopedomAction_depTree.do" style="border: 0;"></iframe>
        </div>

depTree.do在struts.xml中如下配置

<result name="depTree">/WEB-INF/pages/system/deptTree.jsp</result>

在deptTree.jsp中我用ajax发送请求获得部门信息,如下


<HEAD>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/css/dtree.css" type="text/css" />
	<script language="javascript" src="${pageContext.request.contextPath }/script/jquery-1.4.2.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/script/dtree.js"></script>
	<TITLE>亚太广告信息管理系统</TITLE>
</HEAD>
<body>
<div class="dtree">
 
	<p><a href="javascript:d.closeAll();">折叠</a></p>
	
	<script type="text/javascript">
		  var d = new dTree('d');
		$(function(){
		  
			$.post("${pageContext.request.contextPath}/info/SysUserPopedomAction_dept.do",function(data){
				//console.info(data);
				//{"departments":[{"depID":0,"depName":"无","parentID":null},
				//                  {"depID":3,"depName":"财务部","parentID":0},
				//                  {"depID":4,"depName":"销售部","parentID":0},
				//                  {"depID":5,"depName":"编辑部","parentID":3},
				//                  {"depID":6,"depName":"人事部","parentID":0}]}
				
				d.add(0,-1,"亚太广告石家庄分公司");
				for(var i=0;i<data.departments.length;i++){
					if(data.departments[i].depID != "0"){
						//alert(data.departments[i].depID);
						//alert(data.departments[i].depName);
						//alert(data.departments[i].parentID);
						d.add(parseInt(data.departments[i].depID),parseInt(data.departments[i].parentID),data.departments[i].depName);
					}
				}
				
				document.write(d);
			});
			d.openAll();
		});
	</script>
</div>
</body> 
可以显示tree的结构,但是点击时就报未定义异常。 


加载中
0
妞妞超人

研究一天发现不是引入js文件的问题,后来改了一种方法,在action中查询部门信息放入List集合中,放入request.setAttribute中,在jsp页面用循环遍历给tree添加节点。


返回顶部
顶部