This article mainly introduces the relevant information on WeChat applet using picker to encapsulate the three-level linkage example code of provinces and municipalities. Friends in need can refer to the following
WeChat applet uses picker to encapsulate the three-level linkage of provinces and municipalities. Linkage Example
At present, learning mini programs is more about seeing whether other components can be encapsulated twice, which will help to quickly develop various mini program applications in the future. At present, it is found that the selector mode of picker only has one level of drop-down, so can we use three pickers to implement a three-level linkage template and introduce it to other pages? The answer is yes. Then my idea is this:
1. Use template template syntax for encapsulation, and the data is passed in from the page
2. According to the syntax of the picker component , range can only be a set of Chinese region arrays, but we need the unique code of each region to trigger the next level of linkage data. In this way, my approach is to store two object arrays of Chinese names and unique codes through two sets of data tables in one object. Format [province:{code:['110000', '220000'...], name: ['Beijing City', 'Tianjin City'...]}], this format is fixed and needs to be returned by the server.
3. Obtain the next level data through the bindchange event of the picker. Each method is written into the function and exposed for the page to call.
Then let’s talk about it The directory structure of my demo:
common
-net.js//wx.request request interface secondary integration
-cityTemplate.js//Three-level linkage method
page
-demo
-demo.js
-demo.wxml
template
-cityTemplate. wxml
app.js
app.json
app.wxss
Then, use phpstudy to build a simple server for testing. Don't ask me why the server side is like this, I don't understand either. I just want data when I'm just getting started...
Of course you can skip this step and fix the data directly in demo.js for testing. ..
The code is as follows: [The return data format of the server follows the retArr specification below]
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
Connect Down is cityTemplate.wxml::
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 |
|
cityTemplate.js::
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
Shun the net.js method::
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
The core code is the above three files, followed by the demo file for testing:
demo.wxml:
1 2 |
|
demo.js::
##
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 |
|
The implementation of city selection by WeChat mini program imitating Meituan
The implementation of city positioning by WeChat mini program
The above is the detailed content of Implementation of three-level linkage between provinces and municipalities using picker in WeChat mini program. For more information, please follow other related articles on the PHP Chinese website!