动态dtree不显示,麻烦帮我看看,愁死了!!!!!!!
这是生成xml的servlet:
package com.handler;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dao.DaoTest;
import com.dao.Nodes;
public class NodesPrint extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("调用servlet生成xml文件");
request.setCharacterEncoding("utf-8");
response.setContentType("text/xml;charset=utf-8");
//response.setHeader("ContentType","text/xml");
PrintWriter out = response.getWriter();
DaoTest test = new DaoTest();
ArrayList list= test.getNodeInfo();
//System.out.println("#"+list.size()+"#");
if(list!=null&&list.size()>0){
//System.out.println(list.size()+"是长度");
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out.println("<nodes>");
for(int i=0;i<list.size();i++){
Nodes node = (Nodes) list.get(i);
//out.println("<node nodeId='1' parentId='1' hrefAddress='www.baidu.com'>节点</node>");
out.println("<node nodeId='"+node.getClassid()+"'parentId='"+node.getParentid()+"'hrefAddress='"+node.getFormid()+"'>"+node.getClassname()+"</node>");
}
out.println("</nodes>");
}
}
}
这是显示的jsp
<%@ page language="java" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>树形结构</title>
<script type="text/javascript" src="dtree.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<link rel="stylesheet" href="dtree.css" type="text/css"></link>
<script type="text/javascript">
//alert(nodeId+"/"+parentId+"/"+nodeName+"/"+hrefAddress);
tree = new dTree('tree');//创建一个对象.
tree.add(0,-1,"这是根节点");
$.ajax({
url:'NodesPrint',
type:'post', //数据发送方式
dataType:'xml', //接受数据格式
error:function(xml){
alert('Error loading XML document'+xml);
},
async: false ,
success: function(xml){
//alert(xml);
//alert("ok");
$(xml).find("node").each(function(){
var nodeId=$(this).attr("nodeId");
var parentId=$(this).attr("parentId");
//var hrefAddress=$(thiss).attr("hrefAddress");
var nodeName=$(this).text();
tree.add(nodeId,parentId,nodeName,"javaScript:onClickTreeNode();"
,"","","","",false);
});
}
});
document.write(tree);
function hiddeninput1(){
document.getElementById("d2").style.display="none";
document.getElementById("d3").style.display="none";
}
function showinput1(){
document.getElementById("d2").style.display="block";
}
function showinput2(){
document.getElementById("d3").style.display="block";
}
function dele(){
// node=new Node(tree.getSelected());
node=tree.getNodeById(tree.getSelected());
//alert(node._hc);
var t = window.confirm("确认删除此节点?");
if(t==true){
if(node._hc==false){
document.forms.form1.action="servlet/DeleteServlet";
document.form1.submit();
}else{
if(tree.getSelected()==1){
alert("根节点不能删除!");
}else{
alert("此节点下有子节点,不能删除!");
}
}}else{
}
}
function addservlet(){
document.forms.form1.action="servlet/AddServlet";
document.form1.submit();
}
function updateservlet(){
document.forms.form1.action="servlet/UpdateServlet";
document.form1.submit();
}
function onClickTreeNode(){
//alert(tree.getSelected());
//alert(tree.getSelected().name);
document.getElementById("cn").value=tree.getSelected();
}
</script>
</head>
<body onload="hiddeninput1()">
<form name ="form1" action="">
<div align="center" id="d1">
当前节点的id:<input type="text" name="current" id="cn"><br>
<br>
<input type="button" value="修改" id="b1" onclick="showinput1()">
<input type="button" value="删除" id="b2" onclick="dele()">
<input type="button" value="添加子节点" id="b3" onclick="showinput2()"><hr>
</div>
<div id="d2" align="center">
修改的节点的名称是:<input type="text" name="upname" id="updatename"><br><br>
<input type="button" value="确定修改" onclick="updateservlet()">
</div>
<div id="d3" align="center">
添加的节点的名称是:<input type="text" name="adname" id="addname"><br><br>
<input type="button" value="确定添加" onclick="addservlet()">
</div>
</form>
</body>
</html>
帮我看看吧
[解决办法]
用firebug或是调JS的看下
为啥不显示,是引入JS包错了,还是你数据填错了
[解决办法]
out.println("<node nodeId='"+node.getClassid()+"'parentId='"+node.getParentid()+"'hrefAddress='"+node.getFormid()+"'>"+node.getClassname()+"</node>");
你自己的第一node的parentId是不是0?因为 tree.add(0,-1,"这是根节点");
------解决方案--------------------
先手动搞几条数据,看能显示不,能显示了再按规律拼。