Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the cascade selection of treeview by jquery

Shulou Source: shulou.com Published: 2022-06-03 03:53:13 09月25日 Update

This article is about how jquery implements cascading options for treeview. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The use of jquery.treeview is very simple, copy the treeview style file and js into the corresponding project directory first, it should be noted that the p_w_picpaths file and jquery.treeview.css in the same directory, of course, you can also directly modify the path in the css style.

$(document) .ready (function () {$("# jqTree") .treeview ({animated: "fast", persist: "location", collapsed: true, unique: true});})

An example of a directory tree is as follows:

Level 1, level 1, level 2, level 3, level 4, level 4, level 1. Level 4, level 2, level 4, level 4

The key js code is the cascade operation. When I select a node, I should select the corresponding child node and ancestor node accordingly. When I cancel the selection, I should first judge whether there are any selected items under the ancestor node, and if so, I should also cancel the selection of the ancestor node.

Click (function () {/ / descendant directory var c = $(this). Parent (). Find ("input"); var b = $(this) .attr ('checked'); $(this) .attr (' checked', b); c.each (function () {$(this) .attr ('checked', b);}) / / ancestral directory var count = 0; var p = $(this) .ancestor ('li'); / / all ancestral directories p.each (function (I) {if (itemized ancestor directory 0) {} else {var o = $(this). Find (' input'); if (count) {o [0] .ancestor = true } else {o [0] .requests = false;}} var ulChildren = $(this) .parent ('ul'). Find (' input'); count = 0; ulChildren.each (function () {if ($(this) .attr ('checked')) {count++ / / the number of parents of the current node selected}}); Thank you for reading! This is the end of this article on "how to realize the cascade choice of treeview in jquery". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Select directory node ancestor content file more style article good practical number code key descendant article see knowledge example node Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Huawei Xiaomi MariaDB Shulou Technology