This article example shares the application code of jQuery treeview tree structure for your reference. The specific content is as follows Following the application of Bootstrap-treeview, I tried to solve this problem with jquery-treeview and recorded my solution, but it may not be the best. Introduce necessary CSS
Introduce necessary js
Write the page treeview_jQuery.html <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>TreeViewByJQuery</title> <link href="../static/css/jquery.treeview.css" rel="stylesheet"> <script src="../static/js/jquery-3.0.0.js"></script> <script src="../static/js/jquery.treeview.js"></script> </head> <script> $(function () { $.ajax({ type:"GET", url:"/tree/treeView.do", //Backend interface path async:false, //Non-asynchronous dataType:"json", //Data format is json success:function (data) { var html = buildTree(data); //Call buildtree() to build a tree structure $("#tree").append(html); //Append the tree structure to the DOM element } }); $("#tree").treeview({}); //Use jquery.treeview to turn the constructed attribute structure into a dynamic tree }); /* Recursively access the data returned by the background, and construct a tree structure by spelling out HTML code*/ var buildTree = function(data){ var html=""; $.each(data,function(i,n){ //Traverse all tree nodes in the current datahtml = html+"<li><span class=\"folder\">"+n.text+"</span>"; //The current node is the parent nodevar children = buildTree(n.nodes); //Recursively traverse all child nodes of the current nodehtml = html+"<ul>"+children+"</ul>"; //Put the parent node and child node together}) return html; //Return the constructed tree structure} </script> <body> <ul id="tree" class="filetree"></ul> </body> </html> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of Nginx proxy_redirect usage
>>: CentOS7 uses rpm package to install mysql 5.7.18
There is a table user, and the fields are id, nic...
What is "Sticky Footer" The so-called &...
This article shares the specific code of Vue impo...
Table of contents Virtual DOM What is virtual dom...
Table of contents What is JSON Why this technolog...
login.html part: <!DOCTYPE html> <html l...
Because the Base images pulled by Docker, such as...
Preface The mv command is the abbreviation of mov...
Preface This article mainly explains how to imple...
Table of contents 1. Use scripts to encrypt TLS f...
by Take the effect shown in the picture as an exa...
Table of contents 1. Install dependencies 2. Conf...
There was no problem connecting to the database y...
1. Introduction Responsive Web design allows a we...
Solution to 1449 and 1045 exceptions when connect...