This article uses the sample code to introduce in detail how AngularJS can be used to implement a tree structure (ztree) menu. In this article, only a few lines of AngularJS code are used, which is very helpful for daily development, if you need it, you can refer to it for reference. Let's take a look at it. Tree Structure
The tree structure has multiple forms and implementation methods. zTree is simple, elegant, and easy to implement. ZTree is a multi-functional "tree plug-in" implemented by jQuery ". Its biggest advantage is its flexible configuration. A simple parent-child structure can be formed as long as the id and pid values are the same. Coupled with free open source, zTree is becoming increasingly popular.
As follows:
First, you need to know what AngularJS's two-way data binding is to better understand the following code. After a long time, you have come up with the following code to implement the left-side menu tree structure.
To implement the above functions, follow these steps:
Add ng-app to the HTML tag to enable AngularJS to manage the entire HTML document.
MyApp is a module created by myself
The label of the entire menu is as follows:
- Dashboard
- Host
- Container
- Template
- User
- Modify Materials
- Change Password
- Add User
- Message
- Configuration
The JS Code is as follows:
// Create the myApp module var myApp = angular. module ('myapp', []) // create a controller named Left-navigationmyApp.controller ('left-navigation', ['$ scope', function ($ scope) {// define a function navFunc and accept a parameter $ scope. navFunc = function (arg) {// make the navAction variable equal to the value arg $ scope passed in by the function. navAction = arg ;};}]);
Summary
The overall idea is to execute a function when you click the first-level navigation and send the name of the first-level navigation to the function. Then, the second-level navigation is displayed when the navAction variable is equal to its upper-level navigation, otherwise, it will be hidden. The above is all about this article. I hope it will help you in your study or work. If you have any questions, please leave a message.
For more articles on AngularJS Implementation of tree structure (ztree) menu sample code, please follow the PHP Chinese network!