其中提供了一種從后臺取數(shù)據(jù)渲染成樹的形式: 復制代碼 代碼如下: $("#mytree").tree({ data : { type : "json", url : "${ctx}/user/power!list.do" } }); 對于url中返回的 " /> 91婷婷色,国产福利在线观看,成人毛片在线播放

四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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

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

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

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

這里需要一個從后臺實例集合轉(zhuǎn)換為它規(guī)定的json數(shù)據(jù)的形式.
復制代碼 代碼如下:
/** *//**
* 無限遞歸獲得jsTree的json字串
*
* @param parentId
* 父權(quán)限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);
// 有子節(jié)點
if (a.getIshaschild() == 1)
{
str += "{attributes:{id:/"" + a.getAnid()
+ "/"},state:/"open/",data:/"" + a.getAnname() + "/" ,";
str += "children:[";
// 查出它的子節(jié)點
List<Action> list = actionManager.queryByParentId(a.getAnid());
// 遍歷它的子節(jié)點
for (int j = 0; j < list.size(); j++)
{
Action ac = list.get(j);
//還有子節(jié)點(遞歸調(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)用:
復制代碼 代碼如下:
@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)限類等的實體。
效果圖:

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

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

主站蜘蛛池模板: 少妇的诱惑电影| ?1,| creepshow| 电影频道直播| 幸福年民乐合奏曲简谱| 鬼整人| 克里斯蒂娜·阿奎莱拉| 通往幸福的途径电影在线观看| 近郊| 失落的星球| 学霸考砸了被父母打的视频| 浙江地图全图高清版大图| nina hartley| 浙江卫视节目表(全部)| 圆的认识评课| 《完美无瑕》莫妮卡贝鲁奇| 好大一个家 电视剧| 许华升公个人资料身高多少| 欢乐的牧童钢琴谱| 马樱花| 爱在一起麻辣烫| 东方卫视节目表| 黑色纳粹电影完整版| 糯玉米和甜玉米哪个热量高| xxxxxxxxxxxxxxxxx| 韩国青草视频| 校园风暴| 心太狂| 饥渴的少妇电影完整版| 夕阳老人视频| 黄瀞怡| 失落的星球| 暗夜幕后在线观看完整版| 我的公公电影| land of the lost| 吴谨言星座| 恋爱选举巧克力| 别说我的眼泪你无所谓吉他谱| 荆棘花| 无耻之徒英文剧名| 永不瞑目演员表|