ThinkPHP and Ajax realize secondary linkage drop-down menu

不言
Release: 2023-03-30 12:48:02
Original
2286 people have browsed it

This article mainly introduces the drop-down menu for secondary linkage between ThinkPHP and Ajax. It has certain reference value. Now I share it with you. Friends in need can refer to the data existence of

linkage menu. In the database, the menu data can be changed at any time by adding, deleting, modifying, or modifying the database without modifying the code. At the same time, after achieving level 2, level 3 and level 4 can also be achieved. . . Wait for the related menu

The first is the design of the database. The classification table is called cate.

What I am doing is the second-level linkage of classified data. The fields required for the data are: id, name (Chinese name), pid (parent id).

Parent id Settings: If the data does not have an upper level, the parent id is 0. If there is an upper level, the parent id is the id of the upper level.

After the database has content, you can start writing code to implement secondary linkage.

First get all the data with pid 0 in the background php, save it to $cate, and then use a foreach loop to output it in the first layer's