其中提供了一種從后臺取數據渲染成樹的形式: 復制代碼 代碼如下: $("#mytree").tree({ data : { type : "json", url : "${ctx}/user/power!list.do" } }); 對于url中返回的 " /> 男女精品视频,成视频年人黄网站免费视频,成人在线不卡

一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

基于jsTree的無限級樹JSON數據的轉換代碼

jstree 主頁 :
http://www.jstree.com/

其中提供了一種從后臺取數據渲染成樹的形式:
復制代碼 代碼如下:
$("#mytree").tree({
data : {
type : "json",
url : "${ctx}/user/power!list.do"
}
});

對于url中返回的值必須是它定義的json數據形式:
復制代碼 代碼如下:
$("#demo2").tree({
data : {
type : "json",
json : [
{ attributes: { id : "pjson_1" }, state: "open", data: "Root node 1", children : [
{ attributes: { id : "pjson_2" }, data: { title : "Custom icon", icon : "../media/images/ok.png" } },
{ attributes: { id : "pjson_3" }, data: "Child node 2" },
{ attributes: { id : "pjson_4" }, data: "Some other child node" }
]},
{ attributes: { id : "pjson_5" }, data: "Root node 2" }
]
}
});

這里需要一個從后臺實例集合轉換為它規定的json數據的形式.
復制代碼 代碼如下:
/** *//**
* 無限遞歸獲得jsTree的json字串
*
* @param parentId
* 父權限id
* @return
*/
private String getJson(long parentId)
{
// 把頂層的查出來
List<Action> actions = actionManager.queryByParentId(parentId);
for (int i = 0; i < actions.size(); i++)
{
Action a = actions.get(i);
// 有子節點
if (a.getIshaschild() == 1)
{
str += "{attributes:{id:/"" + a.getAnid()
+ "/"},state:/"open/",data:/"" + a.getAnname() + "/" ,";
str += "children:[";
// 查出它的子節點
List<Action> list = actionManager.queryByParentId(a.getAnid());
// 遍歷它的子節點
for (int j = 0; j < list.size(); j++)
{
Action ac = list.get(j);
//還有子節點(遞歸調用)
if (ac.getIshaschild() == 1)
{
this.getJson(ac.getParentid());
}
else
{

str += "{attributes:{id:/"" + ac.getAnid()
+ "/"},state:/"open/",data:/"" + ac.getAnname()
+ "/" " + " }";
if (j < list.size() - 1)
{
str += ",";
}
}
}
str += "]";
str += " }";
if (i < actions.size() - 1)
{
str += ",";
}
}
}
return str;
}

調用:
復制代碼 代碼如下:
@org.apache.struts2.convention.annotation.Action(results =
{ @Result(name = "success", location = "/main/user/action-list.jsp") })
public String list()
{
String str = "[";
// 從根開始
str += this.getJson(0);
str += "]";
this.renderJson(str);
return null;
}

其中Action是菜單類或權限類等的實體。
效果圖:

JavaScript技術基于jsTree的無限級樹JSON數據的轉換代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 亚洲国产精品久久久天堂麻豆 | 中文字幕久久久久久精 | 国产女人天堂 | 欧美xx在线观看 | 亚洲综合色区图片区 | 欧美成年黄网站色高清视频 | 思思久久99热只有精品 | 日韩一区二区三区免费视频 | 自拍偷自拍亚洲精品被多人伦好爽 | 99视频精品在线 | 色99视频| 国产一区美女 | 国产美女在线精品亚洲二区 | 国产色手机在线观看播放 | 天天久久狠狠伊人第一麻豆 | 国产精品999在线 | 国产成人啪午夜精品网站 | 黄色午夜视频 | 国产激情图片 | 91精品啪在线观看国产色 | 婷婷色网站 | 亚洲综合一区二区不卡 | 麻豆亚洲 | 91九色在线视频 | 伊人色在线观看 | 五月婷婷之综合激情 | 美女网站视频黄色 | 欧美人与禽交片在线观看网站 | 四虎影视国产在线观看精品 | 2018狠狠操 | 黄视频网站观看 | 一本加勒比hezyo东京re高清 | jizz亚洲女人高清 | 久久精品国产乱子伦多人 | 国产一区二区三区久久 | 国产黄色片在线播放 | 色婷婷香蕉 | 国产免费91视频 | 精品国产系列在线观看 | 在线播放真实国产乱子伦 | 久久国产成人福利播放 |