search
HomeWeb Front-endJS Tutorialjquery.simple.tree plug-in A simpler and more compatible infinite tree plug-in_jquery

The effect is as follows:

Select:
jquery.simple.tree plug-in A simpler and more compatible infinite tree plug-in_jquery
Drag:
jquery.simple.tree plug-in A simpler and more compatible infinite tree plug-in_jquery
jquery.simple.tree. Official website address: http://news.kg/wp -content/uploads/tree/ (seems like it can no longer be opened), but because the operation is relatively simple, we will use it for now.
As mentioned before, the jquery EasyUI Tree plug-in is simple and easy to use, but it still has many shortcomings after testing.
 For example:
 1. There is a problem with AJAX compatible with IE8.
2. If the asynchronous return data is slow, it may cause loading failure.
3. We only use the Tree function, but its size is really huge. ...
What we need is good compatibility, asynchronous, and small size (there are really few scenarios where Tree is used, so dedicated code files are better.)
Okay, let's start jquery.simple .tree journey:
First, load the files, three in total: CSS, Jquery main file, and its own js file;
Then, the code that defines Tree;
Finally, write The root node HTML code of this tree;
The front-end code is as follows:

Copy code The code is as follows:




Region selection title> <br><link rel="stylesheet" href="/js/simpletree/jquery.simple.tree.css"> <br><script type="text/javascript" src="/js%20/jquery1.4.2.min.js"></script> <br><script type="text/javascript" src="/js/simpletree/jquery.simple.tree.js"> script> <BR><script type="text/javascript"> <BR>var simpleTreeCollection; <BR>$(document).ready(function(){ <BR>simpleTreeCollection = $('.simpleTree'). simpleTree({ <BR>autoclose: true, <BR>afterClick:function(node){ <BR>alert("You selected:" $('span:first',node).text() "id is:" $('span:first',node).attr("id").substr(2));//Why ".substr(2)" is needed here is for special reasons, which can be explained later. If You only need to get the text, you don't need to get the ID here. <BR>}, <BR>afterDblClick:function(node){ <BR>//alert("text-" $('span:first',node).text());//Double-click event<BR>} , <BR>afterMove:function(destination, source, pos){ <BR>//alert("destination-" destination.attr('id') " source-" source.attr('id') " pos-" pos);//Drag event<BR>}, <BR>afterAjax:function() <BR>{ <BR>//alert('Loaded'); <BR>}, <BR>animate:true <BR>//,docToFolderConvert:true <BR>}); <BR>}); <BR></script> <br> <br>

  • Region selection

    • China

      • {url:/common/GetGroupHtmlByPid.ashx? pid=0}









Backend response code:
GetGroupHtmlByPid.ashx.cs
Copy code The code is as follows:

public class GetGroupHtmlByPid : IHttpHandler
{
GroupManager group;
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
int parentId = -1;
int type = 0;
string resultStr = string.Empty;
if (!context.Request.QueryString["pid"].IsNullOrEmpty())
{
Int32.TryParse(context.Request.QueryString["pid"], out parentId);
}
if (!context.Request.QueryString["type"].IsNullOrEmpty())
{
Int32.TryParse(context.Request.QueryString["type"], out type);
}
if (parentId >= 0)
{
try
{
group = new GroupManager((GroupType)type);
var subAg = group.AllGroups.Where(c => c.ParentId == parentId);
resultStr = "
    ";
    foreach (Base_group item in subAg)
    {
    resultStr = "
  • " item.GroupName "";//这里可以解释前台代码为何要.substr(2);
    resultStr = "
    • {url:/common/GetGroupHtmlByPid.ashx?pid=" item.GroupId "}
    ";
    resultStr = "
  • ";
    }
    resultStr = "
";
}
catch (Exception ex)
{
}
}
context.Response.Write(resultStr);
}
public bool IsReusable
{
get
{
return false;
}
}
}

后台看起来有点别扭,因为这个插件本身只支持HTML节点加载的,不过网上有人进行扩展了,用了JSON,不过个人感觉这对速度影响实在微乎其微,还是直接封装出HTML代码的。
总结一下jquery.simple.tree插件的优缺点:
优点:体积小,兼容性高,可异步,支持拖拽。
缺点:如果初始化的时候就需要异步加载,则需要手动更改它的几行代码。例如我的例子中。
本插件还有一个特别的功能,支持拖拽,可以用于后台维护无限分类,非常方便,有待读者自己去发掘,希望本文能够抛砖引玉,对你有所帮助!
源插件下载地址:http://plugins.jquery.com/project/SimpleTree
我的修改后的下载地址:simpletree.rar
我只修改了2行代码,以便在第一次初始化时就加载异步的内容。
Statement
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
Javascript Data Types : Is there any difference between Browser and NodeJs?Javascript Data Types : Is there any difference between Browser and NodeJs?May 14, 2025 am 12:15 AM

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScript Comments: A Guide to Using // and /* */JavaScript Comments: A Guide to Using // and /* */May 13, 2025 pm 03:49 PM

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment