dtree中new dTree('d')报d is not defined? 400 报错
在主页面的左侧加载部门信息
<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" }/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 <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的结构,但是点击时就报未定义异常。
研究一天发现不是引入js文件的问题,后来改了一种方法,在action中查询部门信息放入List集合中,放入request.setAttribute中,在jsp页面用循环遍历给tree添加节点。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。