在编程过程中遇到此问题如下:
1、点击删除之后,数据库开始运做,MyEclipse日志显示正在删数据。后台数据库记录删除。
2、数据库删除之后,jsTree此节点删除,我按F5刷新,此时已经删除的结点又出现。
初步考虑以下几种原因:
1、Jquery版本问题(排除原因:直接将Demo上的Jquery复制下来依旧无效)。
2、Jquery.jstree.js被更改(排除排除:直接将Demo上的Jquery复制下来依旧无效)。
3、ajax方法调用出现问题。
4、CSS问题(排除原因:直接将Demo上的Jquery复制下来依旧无效)。
5、上下文路径问题。
6、IE缓存问题。
7、后台方法问题。
8、Hibernate缓存问题。
9、整体JSP框架问题。(排除原因:直接访问Action依旧无效)。
代码如下:
<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jsTree v.1.0 - full featured demo</title>
<script type="text/javascript" src="js/jquery/jquery.js"></script>
<script type="text/javascript" src="js/jstree/jquery.cookie.js"></script>
<script type="text/javascript" src="js/jstree/jquery.hotkeys.js"></script>
<script type="text/javascript" src="js/jstree/jquery.jstree.js"></script> <style type="text/css">
html, body { margin:0; padding:0; }
body, td, th, pre, code, select, option, input, textarea { font-family:verdana,arial,sans-serif; font-size:10px; }
.demo, .demo input, .jstree-dnd-helper, #vakata-contextmenu { font-size:10px; font-family:Verdana; }
#container { width:780px; margin:10px auto; overflow:hidden; position:relative; }
#demo { width:auto; height:400px; overflow:auto; border:1px solid gray; } #text { margin-top:1px; } #alog { font-size:9px !important; margin:5px; border:1px solid silver; }
</style>
</head>
<body>
<div id="container"><div id="mmenu" style="height:30px; overflow:auto;">
<input type="button" id="add_folder" value="add folder" style="display:block; float:left;"/>
<input type="button" id="add_default" value="add file" style="display:block; float:left;"/>
<input type="button" id="rename" value="rename" style="display:block; float:left;"/>
<input type="button" id="remove" value="remove" style="display:block; float:left;"/>
<input type="button" id="cut" value="cut" style="display:block; float:left;"/>
<input type="button" id="copy" value="copy" style="display:block; float:left;"/>
<input type="button" id="paste" value="paste" style="display:block; float:left;"/>
<input type="button" id="clear_search" value="clear" style="display:block; float:right;"/>
<input type="button" id="search" value="search" style="display:block; float:right;"/>
<input type="text" id="text" value="" style="display:block; float:right;" />
</div><!-- the tree container (notice NOT an UL node) -->
<div id="demo" class="demo"></div>
<!-- JavaScript neccessary for the tree -->
<script type="text/javascript">
$(function () {
$("#demo")
.jstree({ 
"plugins" : [ "themes", "json_data", "ui", "crrm", "cookies", "dnd", "search", "types", "hotkeys", "contextmenu" ],
"json_data" : {
"ajax" : {
"url" : "MenuTreeAction.action",
"data" : function (n) {
alert('测试');
return {
"nodeId" : n.attr ? n.attr("id").replace("node_","") : -1
};
}
}
},
"search" : {
"ajax" : {
"url" : "./server.php",
"data" : function (str) {
return { 
"operation" : "search", 
"search_str" : str 
}; 
}
}
},
"types" : {
"max_depth" : -2,
"max_children" : -2,
"valid_children" : [ "drive" ],
"types" : {
"default" : {
"valid_children" : "none",
"icon" : {
"image" : "./file.png"
}
},
"folder" : {
"valid_children" : [ "default", "folder" ],
"icon" : {
"image" : "./folder.png"
}
},
"drive" : {
"valid_children" : [ "default", "folder" ],
"icon" : {
"image" : "./root.png"
},
"start_drag" : false,
"move_node" : false,
"delete_node" : false,
"remove" : false
}
}
},
"ui" : {
"initially_select" : [ "node_4" ]
},
"core" : {
"initially_open" : [ "node_2" , "node_3" ] 
}
})
.bind("create.jstree", function (e, data) {
$.post(
"./server.php", 

"operation" : "create_node", 
"id" : data.rslt.parent.attr("id").replace("node_",""), 
"position" : data.rslt.position,
"title" : data.rslt.name,
"type" : data.rslt.obj.attr("rel")
}, 
function (r) {
if(r.status) {
$(data.rslt.obj).attr("id", "node_" + r.id);
}
else {
$.jstree.rollback(data.rlbk);
}
}
);
})
.bind("remove.jstree", function (e, data) {
data.rslt.obj.each(function () {
$.ajax({
async : false,
type: 'POST',
url: "sysMenuJsonDelete.action",
data : { 
"bean.id" : this.id
}, 
success : function (r) {
if(!r.status) {
data.inst.refresh();
}
}
});
});
})
.bind("rename.jstree", function (e, data) {
$.post(
"./server.php", 

"operation" : "rename_node", 
"id" : data.rslt.obj.attr("id").replace("node_",""),
"title" : data.rslt.new_name
}, 
function (r) {
if(!r.status) {
$.jstree.rollback(data.rlbk);
}
}
);
})
.bind("move_node.jstree", function (e, data) {
data.rslt.o.each(function (i) {
$.ajax({
async : false,
type: 'POST',
url: "./server.php",
data : { 
"operation" : "move_node", 
"id" : $(this).attr("id").replace("node_",""), 
"ref" : data.rslt.np.attr("id").replace("node_",""), 
"position" : data.rslt.cp + i,
"title" : data.rslt.name,
"copy" : data.rslt.cy ? 1 : 0
},
success : function (r) {
if(!r.status) {
$.jstree.rollback(data.rlbk);
}
else {
$(data.rslt.oc).attr("id", "node_" + r.id);
if(data.rslt.cy && $(data.rslt.oc).children("UL").length) {
data.inst.refresh(data.inst._get_parent(data.rslt.oc));
}
}
$("#analyze").click();
}
});
});
});
});
</script>
<script type="text/javascript">
$(function () { 
$("#mmenu input").click(function () {
switch(this.id) {
case "add_default":
case "add_folder":
$("#demo").jstree("create", null, "last", { "attr" : { "rel" : this.id.toString().replace("add_", "") } });
break;
case "search":
$("#demo").jstree("search", document.getElementById("text").value);
break;
case "text": break;
default:
$("#demo").jstree(this.id);
break;
}
});
});
</script><div style="position:absolute; right:30px; top:120px; width:220px; border:1px solid silver; min-height:160px;">
<input type="button" style='display:block; width:170px; height:24px; margin:5px auto;' value="reconstruct" onclick="$.get('./server.php?reconstruct', function () { $('#demo').jstree('refresh',-1); });" />
<input type="button" style='display:block; width:170px; height:24px; margin:5px auto;' id="analyze" value="analyze" onclick="$('#alog').load('./server.php?analyze');" />
<input type="button" style='display:block; width:170px; height:24px; margin:5px auto;' value="refresh" onclick="$('#demo').jstree('refresh',-1);" />
<div id='alog'></div>
</div><p style="margin:1em 2em 3em 2em; text-align:center; ">If you like the project - consider <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&[email protected]&currency_code=USD&amount=&return=http://jstree.com/donation&item_name=Buy+me+a+coffee+for+jsTree">supporting jstree</a>.</p></div></body>
</html>