Home > Web Front-end > JS Tutorial > Conversion code of infinite tree JSON data based on jsTree_javascript skills

Conversion code of infinite tree JSON data based on jsTree_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 18:22:22
Original
1264 people have browsed it

jstree
* Infinite recursion to obtain the json string of jsTree
*
* @param parentId
* Parent permission id


Copy code


The code is as follows:


$("# mytree").tree({
data:{
type:"json",
url :"${ctx}/user/power!list.do"

Copy code


The code is as follows:


$("#demo2").tree({
data:{
type:"json",
json:[
{attributes:{id:"pjson_1" },state:"open",data:"Rootnode1",children:[
{attributes:{id:"pjson_2"},data:{title :"Customicon",icon:"../media/images/ok.png"}},
{attributes:{id:"pjson_3"},data:"Childnode2"},
{attributes:{id:"pjson_4"},data:"Someotherchildnode"}
]},
{attributes:{id:"pjson_5"},data:"Rootnode2"}
]

Copy the code


The code is as follows:


/***//**
*Infinite recursion to obtain the json string of jsTree
*
*@paramparentId
*parent permission id
*@return
*/
privateStringgetJson(longparentId)
{
//Check out the top level
Listactions=actionManager.queryByParentId(parentId);
for(inti=0;i{
Actiona=actions.get(i);
//has child nodes
if(a.getIshaschild()==1)
{
str="{attributes:{id:" "a.getAnid()
""}, state: "open", data: "" a.getAnname()"",";
str="children:[";
//Find out its child nodes
Listlist=actionManager.queryByParentId(a.getAnid());
//Traverse its child nodes
for(intj=0;j{
Actionac=list.get(j);
//There are also child nodes (recursive call)
if(ac.getIshaschild()==1)
{
this.getJson(ac.getParentid());
}
else
{

str= "{attributes:{id:""ac.getAnid()
""},state:"open",data: ""ac.getAnname()
""""}";
if(j{
str=",";
}
}
}
str= "]";
str="}";
if(i{
str=",";
}
}
}
returnstr;}Call:

Copy code


The code is as follows:


@org.apache.struts2 .convention.annotation.Action(results=
{@Result(name="success",location="/ main/user/action-list.jsp")})
publicStringlist()
{
String str="[";
//Start from root
str=this.getJson(0);
str="]";
this.renderJson(str);
returnnull;Conversion code of infinite tree JSON data based on jsTree_javascript skills}where Action is an entity such as menu class or permission class. Rendering:
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template