IntegrationLayui TP5.1
, sometimes it is necessary to call the column number, which requires dynamic call of data. I have tried many methods before, but none of them worked. I checked the JS data call later. method, combined with layui and tried many times, finally found a way to achieve this function, I hope it will be useful to everyone.
The following example is an example of calling a city. The database fields include: id, order (sort), pid (upper-level city ID), name (city name), which includes provincial, municipal, and county levels. /District-level and third-level cities.
Step one: According to the method given by Layui, first write the HTML page, as shown below:
where ___ADMIN__
is yourself Just modify the configured style path to your own path. In addition, since the data calling here uses js data calling, the jquery library needs to be loaded. I am using jquery-3.2.1
here. You can load the corresponding version of jquery according to your actual needs.
Library, not much to say here, just go to the code:
[HTML]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
Step 2: Write the background PHP code , here I wrote the code according to the rules of TP5.1
[PHP code]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
A method was used above:getAllParentId
, this method is specially used to get all parent IDs. The following is the code information:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
You can try it, I hope it can help you. What I am here is a cyclic output of city information. You can also try to output other information. You only need to modify the data calling rules. However, it should be noted that no matter how you call the parent and child, they must exist.
Thanks!
Related recommendations: The latest 10 thinkphp video tutorials
The above is the detailed content of TP5.1+layui realizes the calling of column number. For more information, please follow other related articles on the PHP Chinese website!