


ztree implements permission horizontal display function example sharing
When I was working on the permission function recently, I used ztree to implement it, but the product requires that the last layer of permission nodes be displayed horizontally. Below, the editor will share with you the implementation ideas for implementing the horizontal display function of permissions based on ztree for your reference. I hope it can help you.
Recently, when I was working on the permission function, I used ztree to implement it, but the product requires that the permission nodes on the last layer be displayed horizontally. The solution I started looking for online was to use CSS styles to set the display of the last layer to inline. Checked it on my local computer. The effect is good.
However, when I later tested this function on a laptop from ten years ago, I found a special card that caused the browser to crash. So, performance optimization begins.
1. Synchronization is changed to asynchronous. Although it is not stuck, the function is not satisfactory. Many people check a parent node (module node) and save it. At this time, there are no child nodes at all, so the saved data is problematic.
2. Set showIcon and showLine to false, and found that the speed has improved a little, but the product is still not satisfactory.
3. After careful inspection, ztree’s checkboxes are all simulated with span, and a background image is created. Intuitively, I feel that using the native checkbox is better than using image simulation. Just do it, I found an example provided by ztree, and after a slight modification, the effect is still obvious. The main method used is addDiyDom.
Post the main code below.
1. The data structure requires an isLeaf node to mark whether it is a child node.
var zNodes =[ { id:1, pId:0, name:"父节点 1", open:true,isLeaf:false}, { id:11, pId:1, name:"叶子节点 1-1",isLeaf:true}, { id:12, pId:1, name:"叶子节点 1-2",open:true,isLeaf:false}, { id:120, pId:12, name:"叶子节点 1-2-0",isLeaf:true}, { id:121, pId:12, name:"叶子节点 1-2-1",isLeaf:true}, { id:13, pId:1, name:"叶子节点 1-3",isLeaf:true}, { id:2, pId:0, name:"父节点 2", open:true,isLeaf:false}, { id:21, pId:2, name:"叶子节点 2-1",isLeaf:true}, { id:22, pId:2, name:"叶子节点 2-2",isLeaf:true}, { id:23, pId:2, name:"叶子节点 2-3",isLeaf:true}, { id:3, pId:0, name:"父节点 3", open:true,isLeaf:false}, { id:31, pId:3, name:"叶子节点 3-1",isLeaf:true}, { id:32, pId:3, name:"叶子节点 3-2",isLeaf:true}, { id:33, pId:3, name:"叶子节点 3-3",isLeaf:true} ];
2. addDiyDom method
function addDiyDom(treeId, treeNode) { //console.log(treeNode); var aObj = $("#" + treeNode.tId + IDMark_A); var editStr = $("<input type='checkbox' class='checkboxBtn' id='checkbox_" +treeNode.id+ "' onclick='checkedHandler(this)' ></input>"); editStr.data("treeNode",treeNode); aObj.before(editStr); }
3. Several cascade operation methods written by myself
function checkedHandler(checkbox){ var $checkbox = $(checkbox), treeNode = $checkbox.data("treeNode"), state = checkbox.checked; if(treeNode.isLeaf){ //子节点 if(state){ //子节点选中,父节点要跟着选中,子节点取消选择,父节点不用级联 setParentNodeChecked(checkbox); } }else{ //父节点 if(state){ //选中,级联子节点,级联父节点 setParentNodeChecked(checkbox); setChildNodeChecked(checkbox); }else{ setChildNodeChecked(checkbox); } } } /**设置父节点选中 */ function setParentNodeChecked(checkbox){ var $pNode = $(checkbox).closest("ul").parent(); var pCheckbox = $pNode.find(".checkboxBtn").get(0); var treeNode = $(pCheckbox).data("treeNode"); if(pCheckbox.checked === checkbox.checked) return; pCheckbox.checked = checkbox; if(treeNode.pId != "0") setParentNodeChecked(pCheckbox); } /**设置子节点选中 */ function setChildNodeChecked(checkbox){ $(checkbox).closest("li").find(".checkboxBtn").each(function(){ this.checked = checkbox.checked; }); }
4. In css, set:
.ztree li.isLeaf{ display:inline; }
Related recommendations:
Detailed example explanation jQuery EasyUI combined with zTree tree structure to create a web page
zTree asynchronous loading and expansion of the first level node method implementation
Example explanation jQuery uses the zTree plug-in to implement drag-and-drop functionality
The above is the detailed content of ztree implements permission horizontal display function example sharing. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When you click the search field in Windows 11, the search interface automatically expands. It displays a list of recent programs on the left and web content on the right. Microsoft displays news and trending content there. Today's check promotes Bing's new DALL-E3 image generation feature, the "Chat Dragons with Bing" offer, more information about dragons, top news from the Web section, game recommendations, and the Trending Search section. The entire list of items is independent of your activity on your computer. While some users may appreciate the ability to view news, all of this is abundantly available elsewhere. Others may directly or indirectly classify it as promotion or even advertising. Microsoft uses interfaces to promote its own content,

In iOS 17 Apple is introducing Standby Mode, a new display experience designed for charging iPhones in a horizontal orientation. In this position, the iPhone is able to display a series of full-screen widgets, turning it into a useful home hub. Standby mode automatically activates on an iPhone running iOS 17 placed horizontally on the charger. You can view time, weather, calendar, music controls, photos, and more. You can swipe left or right through the available standby options and then long press or swipe up/down to customize. For example, you can choose from analog view, digital view, bubble font, and daylight view, where the background color changes based on time as time passes. There are some options

Microsoft's Windows 11 operating system may periodically display suggestions as pop-ups on your computer using the notification system. The suggestions system, originally intended to provide users with tips and suggestions for improving their Windows 11 workflows, has almost completely transformed into an advertising system to promote Microsoft services and products. Suggestion pop-ups might advertise a Microsoft 365 subscription to users, suggest linking an Android phone to the device, or set up a backup solution. If these pop-ups annoy you, you can tweak your system to disable them entirely. The following guide provides recommendations on disabling pop-ups on devices running Microsoft’s Windows 11 operating system.

What happens when the desktop layout is locked? When using the computer, sometimes we may encounter the situation where the desktop layout is locked. This problem means that we cannot freely adjust the position of desktop icons or change the desktop background. So, what exactly is going on when it says that the desktop layout is locked? 1. Understand the desktop layout and locking functions. First, we need to understand the two concepts of desktop layout and desktop locking. Desktop layout refers to the arrangement of various elements on the desktop, including shortcuts, folders, widgets, etc. we can be free

How to turn on live subtitles instantly in Windows 11 1. Press Ctrl+L on your keyboard 2. Click Agree 3. A popup will appear saying Ready to add subtitles in English (US) (depending on your preferred language) 4. Additionally, you can filter profanity by clicking the gear button? Preference? Filtering Swear Words Related Articles How to Fix Activation Error Code 0xc004f069 in Windows Server The activation process on Windows sometimes takes a sudden turn to display an error message containing this error code 0xc004f069. Although the activation process is online, some older systems running Windows Server may experience this issue. Pass these preliminary checks and if these checks do not

There are many users using Remote Desktop Connection. Many users will encounter some minor problems when using it, such as the other party's taskbar not being displayed. In fact, it is probably a problem with the other party's settings. Let's take a look at the solutions below. How to display the other party's taskbar during Remote Desktop Connection: 1. First, click "Settings". 2. Then open "Personalization". 3. Then select "Taskbar" on the left. 4. Turn off the Hide Taskbar option in the picture.

In Linux systems, you can use the pwd command to display the current path. The pwd command is the abbreviation of PrintWorkingDirectory and is used to display the path of the current working directory. Enter the following command in the terminal to display the current path: pwd After executing this command, the terminal will display the full path of the current working directory, such as: /home/user/Documents. In addition, you can use some other options to enhance the functionality of the pwd command. For example, the -P option can display

You don’t need to enter the WIFI password often, so it’s normal to forget it. Today I will teach you the simplest way to find the password of your own WIFI. It can be done in 3 seconds. To check the WIFI password, use WeChat to scan it. The premise of this method is: there must be a mobile phone that can connect to WIFI. Okay, let’s start the tutorial: Step 1. We enter the phone, pull down from the top of the phone, bring up the status bar, and the WIFI icon. Step 2. Long press the WIFI icon to enter the WLAN settings; long press the WIFI icon. Step 3. Click Connected. Enter the WIFI name of your home, click Share Password, and a QR code will pop up; Step 4 of sharing WIFI password, we take a screenshot and save this QR code; Step 5, long press the WeChat icon on the desktop, and click Scan
