其中提供了一種從后臺取數據渲染成樹的形式: 復制代碼 代碼如下: $("#mytree").tree({ data : { type : "json", url : "${ctx}/user/power!list.do" } }); 對于url中返回的 " /> 欧美视频亚洲视频,国产日韩在线视频,精品一级

中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

基于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數據的轉換代碼,轉載需保留來源!

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

主站蜘蛛池模板: 日韩在线看片 | 亚洲欧美一区二区三区在线 | 日韩在线小视频 | 日本综合在线观看 | 午夜免费福利影院 | 黑人一级片视频 | 亚洲一区二区不卡在线观看 | 午夜一区二区三区在线观看 | 国产中文视频 | 国产一区二区三区在线 | 亚洲3级 | 三级视频久久 | 国产黄色一级电影 | 美女在线一区二区 | 在线免费观看日本视频 | 欧美视频在线一区 | 久精品久久 | 国产免费色 | 午夜网站视频 | 99只有精品| 久久久不卡网国产精品一区 | 国产高清在线精品一区二区三区 | 亚洲午夜精品一区二区三区他趣 | 日韩欧美中文字幕在线观看 | 成人免费视频观看视频 | 特黄特黄a级毛片免费专区 av网站免费在线观看 | 在线视频亚洲 | 精品视频一区在线 | 亚洲一区二区三区高清 | 国产欧美精品 | 国产精品美女久久久av超清 | 美女艹b| 一区二区三区视频在线 | 一二区成人影院电影网 | 一区二区精品在线 | 99久久精品国产一区二区三区 | 精品免费国产一区二区三区四区介绍 | h视频在线免费 | 91不卡在线| 在线观看中文字幕 | 亚洲视频在线观看 |