<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CMS 後台管理工作平台</title>
<script type="text/javascript" src="js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="js/jquery.jstree.js"></script>
<script language="javascript">
//第二種寫法,注意是添加attr
$(function() {
//將menuContainer變成一棵樹!
$("#demo").jstree( {
"json_data" : {
"ajax" : {
"url" : "XXXX.action?method:tree"
}
},
"plugins" : [ "themes", "json_data" ]
});
});
</script>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
font-size: 12px;
}
-->
</style>
</head>
<body>
<div id="demo">
</div>
</body>
</html>
伺服器端:
{
try
{
//添加資料
Node root = new Node("大學",1,"www.baidu.com");
root.addChildNode(new Node("辦公室",2,"www.csdn.com"));
root.addChildNode(new Node("學籍科",3,"www.sina.com"));
//把儲存的資料解析存到JSON 中
String str = JSONMapper.toJSON(root).render(false);
//設定編碼方式
ServletActionContext.getResponse().setCharacterEncoding("UTF-8");
ServletActionContext.getResponse().getWriter().print(str);
} catch (MapperException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}