0
如何實現Struts2Jquery js樹生成一棵樹和一個函數綁定到節點?Struts2JQuery JS樹代及結合
如何實現Struts2Jquery js樹生成一棵樹和一個函數綁定到節點?Struts2JQuery JS樹代及結合
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sjt" uri="/struts-jquery-tree-tags"%>
<html>
<head>
<sj:head />
<script type="text/javascript"
src="http://www.trendskitchens.co.nz/jquery/contextmenu/jquery.contextmenu.r2.packed.js"></script>
<script type='text/javascript'>
jQuery(document).ready(function() {
jQuery.struts2_jquery.require("js/struts2/jquery.tree.struts2-3.2.1"
+ jQuery.struts2_jquery.minSuffix + ".js");
//Binding a function to the click of the nodes
$.subscribe('clickFunction', function(event,element) {
var key = $(".jstree-clicked").parent().attr("key");
foo(key);
});
refreshTree(id);
});
function foo(key) {
alert(key);
}
// This function is used to draw the tree and can also be called to refresh the tree.
function refreshTree(id) {
var options_jsonTree = {};
options_jsonTree.treetheme = "default";
options_jsonTree.url = "StrutsAction.action?id=" + id;
options_jsonTree.onclick = "clickFunction";
options_jsonTree.plugins = "contextmenu";
options_jsonTree.jqueryaction = "tree";
options_jsonTree.id = "jsonTree";
jQuery.struts2_jquery_tree.bind(jQuery('#jsonTree'),options_jsonTree);
}
</script>
</head>
<body>
<div id="jsonTree"></div>
</body>
</html>