


A brief discussion on how to use the styled tree plug-in bootstrap-treeview
Related recommendations: "bootstrap basic tutorial"
bootstrap-treeview is a very cool jQuery multi-view based on bootstrap Level list tree plug-in, this jQuery plug-in is based on Twitter Bootstrap. The purpose of writing this article is to record the usage method for future reference.
1. Plug-in official website: https://jquery-plugins.net/bootstrap-tree-view
2. Demo example: http:// jonmiles.github.io/bootstrap-treeview/
3. Dependencies:
Bootstrap v3.3.4 (>= 3.0.0) jQuery v2.1.3 (>= 1.9.0)
4. Usage:
1. HTML file introduces dependencies:
<link rel="stylesheet" href="css/bootstrap.min.css" /> <link rel="stylesheet" href="css/bootstrap-treeview.min.css" /> <script type="text/javascript" src="js/jquery-3.2.1.js"></script> <script type="text/javascript" src="js/bootstrap.min.js" ></script> <script type="text/javascript" src="js/bootstrap-treeview.min.js" ></script>
2. Sets a DOM element to receive tree data:
<div id="tree"></div>
3. Usage format:
$('#tree').treeview(options); //其中options选项允许用户定制treeview的默认外观和行为。它们在初始化时作为一个对象被传递给插件。
4. Usage example ( js dynamically obtains background data and renders the tree structure):
$(function() { $('#tree').treeview({ data: getTree()//节点数据 }); }) function getTree() { //节点上的数据遵循如下的格式: var tree = [{ text: "Node 1", //节点显示的文本值 string icon: "glyphicon glyphicon-play-circle", //节点上显示的图标,支持bootstrap的图标 string selectedIcon: "glyphicon glyphicon-ok", //节点被选中时显示的图标 string color: "#ff0000", //节点的前景色 string backColor: "#1606ec", //节点的背景色 string href: "#http://www.baidu.com", //节点上的超链接 selectable: true, //标记节点是否可以选择。false表示节点应该作为扩展标题,不会触发选择事件。 string state: { //描述节点的初始状态 Object checked: true, //是否选中节点 /*disabled: true,*/ //是否禁用节点 expanded: true, //是否展开节点 selected: true //是否选中节点 }, tags: ['标签信息1', '标签信息2'], //向节点的右侧添加附加信息(类似与boostrap的徽章) Array of Strings nodes: [{ text: "Child 1", nodes: [{ text: "Grandchild 1" }, { text: "Grandchild 2" }] }, { text: "Child 2" }] }, { text: "Parent 2", nodes: [{ text: "Child 2", nodes: [{ text: "Grandchild 3" }, { text: "Grandchild 4" }] }, { text: "Child 2" }] }, { text: "Parent 3" }, { text: "Parent 4" }, { text: "Parent 5" }]; return tree; }
5. Other instructions:
1. Detailed explanation of parameters (available parameters):
var options = { data: data, //data属性是必须的,是一个对象数组 Array of Objects. color: "", //所有节点使用的默认前景色,这个颜色会被节点数据上的backColor属性覆盖. String backColor: "#000000", //所有节点使用的默认背景色,这个颜色会被节点数据上的backColor属性覆盖. String borderColor: "#000000", //边框颜色。如果不想要可见的边框,则可以设置showBorder为false。 String nodeIcon: "glyphicon glyphicon-stop", //所有节点的默认图标 checkedIcon: "glyphicon glyphicon-check", //节点被选中时显示的图标 String collapseIcon: "glyphicon glyphicon-minus", //节点被折叠时显示的图标 String expandIcon: "glyphicon glyphicon-plus", //节点展开时显示的图标 String emptyIcon: "glyphicon", //当节点没有子节点的时候显示的图标 String enableLinks: false, //是否将节点文本呈现为超链接。前提是在每个节点基础上,必须在数据结构中提供href值。 Boolean highlightSearchResults: true, //是否高亮显示被选中的节点 Boolean levels: 2, //设置整棵树的层级数 Integer multiSelect: false, //是否可以同时选择多个节点 Boolean onhoverColor: "#F5F5F5", //光标停在节点上激活的默认背景色 String selectedIcon: "glyphicon glyphicon-stop", //节点被选中时显示的图标 String searchResultBackColor: "", //当节点被选中时的背景色 searchResultColor: "", //当节点被选中时的前景色 selectedBackColor: "", //当节点被选中时的背景色 selectedColor: "#FFFFFF", //当节点被选中时的前景色 showBorder: true, //是否在节点周围显示边框 showCheckbox: false, //是否在节点上显示复选框 showIcon: true, //是否显示节点图标 showTags: false, //是否显示每个节点右侧的标记。前提是这个标记必须在每个节点基础上提供数据结构中的值。 uncheckedIcon: "glyphicon glyphicon-unchecked", //未选中的复选框时显示的图标,可以与showCheckbox一起使用 }
2. Detailed explanation of methods (list of available methods):
1. checkAll(options);//选中所有树节点 2. checkNode(node | nodeId, options); //选中一个给定nodeId的树节点 3. clearSearch();//清除查询结果 4. collapseAll(options);//折叠所有树节点 5. collapseNode(node | nodeId, options);//折叠一个给定nodeId的树节点和它的子节点 6. disableAll(options);//禁用所有树节点 7. disableNode(node | nodeId, options);//禁用一个给定nodeId的树节点 8. enableAll(options);//激活所有树节点 9. enableNode(node | nodeId, options);//激活给定nodeId的树节点 10. expandAll(options);//展开所有节点 11. expandNode(node | nodeId, options);//展开给定nodeId的树节点 12. getCollapsed();//返回被折叠的树节点数组 13. getDisabled();//返回被禁用的树节点数组 14. getEnabled();//返回被激活的树节点数组 15. getExpanded();//返回被展开的树节点数组 16. getNode(nodeId);//返回与给定节点id相匹配的单个节点对象。 17. getParent(node | nodeId);//返回给定节点id的父节点 18. getSelected();//返回被选定节点的数组。 19. getSiblings(node | nodeId);//返回给定节点的兄弟节点数组 20. getUnselected();//返回未选择节点的数组 21. remove();//删除the tree view component.删除绑定的事件,内部附加的对象,并添加HTML元素。 22. revealNode(node | nodeId, options);//显示给定的树节点,将树从节点扩展到根。 23. search(pattern, options);//在树视图中搜索匹配给定字符串的节点,并在树中突出显示它们。返回匹配节点的数组。 24. selectNode(node | nodeId, options);//选择一个给定的树节点 25. toggleNodeChecked(node | nodeId, options);//Toggles a nodes checked state; checking if unchecked, unchecking if checked. 26. toggleNodeDisabled(node | nodeId, options);//切换节点的禁用状态; 27. toggleNodeExpanded(node | nodeId, options);//切换节点的展开与折叠状态 28. toggleNodeSelected(node | nodeId, options);//切换节点的选择状态 29. uncheckAll(options);//不选所有节点 30. uncheckNode(node | nodeId, options);//不选给定nodeId的节点 31. unselectNode(node | nodeId, options);//不选给定nodeId的节点 说明:可以通过两种方式来调用方法: 1、插件包装器:插件的包装器可以作为访问底层方法的代理。 $('#tree').treeview('methodName', args); 其中,多个参数必须使用数组对象来传入。 2、直接使用treeview:你可以通过下面两种方法中的一种来获取treeview对象实例: //该方法返回一个treeview的对象实例 $('#tree').treeview(true).methodName(args); //对象实例也保存在DOM元素的data中, 可以使用'treeview'的id来访问它。 $('#tree').data('treeview').methodName(args);
3. Detailed explanation of events (list of available events):
1. nodeChecked (event, node) - 一个节点被checked. 2. nodeUnchecked (event, node) - 一个节点被unchecked. 3. nodeCollapsed (event, node) - 一个节点被折叠. 4. nodeDisabled (event, node) - 一个节点被禁用. 5. nodeEnabled (event, node) - 一个节点被启用. 6. nodeExpanded (event, node) - 一个节点被展开. 7. nodeSelected (event, node) - 一个节点被选择. 8. nodeUnselected (event, node) - 取消选择一个节点. 9. searchComplete (event, results) - 搜索完成之后触发. 10. searchCleared (event, results) - 搜索结果被清除之后触发. 说明:事件的调用有两种方式: 第 1 种:在参数中使用回调函数来绑定任何事件: $('#tree').treeview({ //命名约定:以on为前缀,并将事件名的第一个字母转为大写,例如: nodeSelected -> onNodeSelected onNodeSelected:function(event, data) { // 事件代码... } }); 第 2 种:使用标准的jQuery .on()方法来绑定事件: $('#tree').on('nodeSelected',function(event, data) { // 事件代码... });
6. Complete demo download
https://download.csdn.net/download/security_2015/10281802
For more programming-related knowledge, please visit: Programming Learning! !
The above is the detailed content of A brief discussion on how to use the styled tree plug-in bootstrap-treeview. For more information, please follow other related articles on the PHP Chinese website!

The main purpose of Bootstrap is to help developers quickly build responsive, mobile-first websites. Its core functions include: 1. Responsive design, which realizes layout adjustments of different devices through a grid system; 2. Predefined components, such as navigation bars and modal boxes, ensure aesthetics and cross-browser compatibility; 3. Support customization and extensions, and use Sass variables and mixins to adjust styles.

Bootstrap is better than TailwindCSS, Foundation, and Bulma because it is easy to use and quickly develop responsive websites. 1.Bootstrap provides a rich library of predefined styles and components. 2. Its CSS and JavaScript libraries support responsive design and interactive functions. 3. Suitable for rapid development, but custom styles may be more complicated.

Integrating Bootstrap in React projects can be done in two ways: 1) introduced using CDN, suitable for small projects or rapid prototyping; 2) installation using npm package manager, suitable for scenarios that require deep customization. With these methods, you can quickly build beautiful and responsive user interfaces in React.

Advantages of integrating Bootstrap into React projects include: 1) rapid development, 2) consistency and maintainability, and 3) responsive design. By directly introducing CSS files or using the React-Bootstrap library, you can use Bootstrap's components and styles efficiently in your React project.

Bootstrap is a framework developed by Twitter to help quickly build responsive, mobile-first websites and applications. 1. Ease of use and rich component libraries make development faster. 2. The huge community provides support and solutions. 3. Introduce and use class names to control styles through CDN, such as creating responsive grids. 4. Customizable styles and extension components. 5. Advantages include rapid development and responsive design, while disadvantages are style consistency and learning curve.

Bootstrapisafree,open-sourceCSSframeworkthatsimplifiesresponsiveandmobile-firstwebsitedevelopment.Itofferspre-styledcomponentsandagridsystem,streamliningthecreationofaestheticallypleasingandfunctionalwebdesigns.

What makes web design easier is Bootstrap? Its preset components, responsive design and rich community support. 1) Preset component libraries and styles allow developers to avoid writing complex CSS code; 2) Built-in grid system simplifies the creation of responsive layouts; 3) Community support provides rich resources and solutions.

Bootstrap accelerates web development, and by providing predefined styles and components, developers can quickly build responsive websites. 1) It shortens development time, such as completing the basic layout within a few days in the project. 2) Through Sass variables and mixins, Bootstrap allows custom styles to meet specific needs. 3) Using the CDN version can optimize performance and improve loading speed.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use