其中提供了一種從后臺(tái)取數(shù)據(jù)渲染成樹的形式: 復(fù)制代碼 代碼如下: $("#mytree").tree({ data : { type : "json", url : "${ctx}/user/power!list.do" } }); 對(duì)于url中返回的 " /> 欧美精品激情视频,欧美少妇性xxxx,一区二区在线电影

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

基于jsTree的無(wú)限級(jí)樹JSON數(shù)據(jù)的轉(zhuǎn)換代碼

jstree 主頁(yè) :
http://www.jstree.com/

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

對(duì)于url中返回的值必須是它定義的json數(shù)據(jù)形式:
復(fù)制代碼 代碼如下:
$("#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" }
]
}
});

這里需要一個(gè)從后臺(tái)實(shí)例集合轉(zhuǎn)換為它規(guī)定的json數(shù)據(jù)的形式.
復(fù)制代碼 代碼如下:
/** *//**
* 無(wú)限遞歸獲得jsTree的json字串
*
* @param parentId
* 父權(quán)限id
* @return
*/
private String getJson(long parentId)
{
// 把頂層的查出來(lái)
List<Action> actions = actionManager.queryByParentId(parentId);
for (int i = 0; i < actions.size(); i++)
{
Action a = actions.get(i);
// 有子節(jié)點(diǎn)
if (a.getIshaschild() == 1)
{
str += "{attributes:{id:/"" + a.getAnid()
+ "/"},state:/"open/",data:/"" + a.getAnname() + "/" ,";
str += "children:[";
// 查出它的子節(jié)點(diǎn)
List<Action> list = actionManager.queryByParentId(a.getAnid());
// 遍歷它的子節(jié)點(diǎn)
for (int j = 0; j < list.size(); j++)
{
Action ac = list.get(j);
//還有子節(jié)點(diǎn)(遞歸調(diào)用)
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;
}

調(diào)用:
復(fù)制代碼 代碼如下:
@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是菜單類或權(quán)限類等的實(shí)體。
效果圖:

JavaScript技術(shù)基于jsTree的無(wú)限級(jí)樹JSON數(shù)據(jù)的轉(zhuǎn)換代碼,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 巴彦淖尔市| 牟定县| 鸡西市| 江北区| 黄浦区| 南投市| 桃江县| 周宁县| 怀来县| 莱西市| 东宁县| 景德镇市| 天全县| 西昌市| 柘荣县| 石景山区| 漳平市| 新乡县| 南宫市| 武宣县| 饶河县| 平潭县| 乐山市| 通道| 龙游县| 华安县| 大英县| 漳州市| 霍林郭勒市| 南华县| 稷山县| 榆社县| 资阳市| 静安区| 甘泉县| 铁岭市| 巫山县| 德令哈市| 桑植县| 北碚区| 中山市|