vue-next-admin, based on vue3.x + CompositionAPI + typescript + vite + element plus + vue-router-next + next.vuex, is an open source free template library for mobile phones, tablets and PCs 1. Effect diagram (multiple columns)2. Normal selector: mode = selector, multi-column selector: mode = multiSelector Document address: WeChat development document
The format is incorrect and needs to be processed into the corresponding array format. The following is a pit diagram: 3. app.json{ "pages": [ "pages/index/index", "pages/logs/logs", "pages/picker/picker" ], "entryPagePath": "pages/picker/picker", "window": { "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "Weixin", "navigationBarTextStyle": "black" }, "sitemapLocation": "sitemap.json", "usingComponents": { "van-button": "@vant/weapp/button/index", "van-area": "@vant/weapp/area/index" } } 4. picker.wxml<!--pages/picker/picker.wxml--> <view> <view class="section__title">Multi-column selector</view> <picker mode="multiSelector" bindchange="bindMultiPickerChange" bindcolumnchange="bindMultiPickerColumnChange" value="{{multiIndex}}" range="{{newArr}}"> <view class="picker"> Current selection: <van-button type="primary"> {{newArr[0][multiIndex[0]]}}, {{newArr[1][multiIndex[1]]}}, {{newArr[2][multiIndex[2]]}}</van-button> </view> </picker> </view> 5. picker.js
Pay attention to the array format: // pages/picker/picker.js Page({ /** * Initial data of the page */ data: { multiArray: [{ id: 1, label: "Southeast", children: [{ id: 2, label: "Shanghai", children: [{ id: 3, label: "Putuo", }, { id: 4, label: "Huangpu", }, { id: 5, label: "Xuhui", }, ], }, { id: 7, label: "Jiangsu", children: [{ id: 8, label: "Nanjing", }, { id: 9, label: "Suzhou", }, { id: 10, label: "Wuxi", }, ], }, { id: 12, label: "Zhejiang", children: [{ id: 13, label: "Hangzhou", }, { id: 14, label: "Ningbo", }, { id: 15, label: "Jiaxing", }, ], }, ], }, { id: 17, label: "Northwest", children: [{ id: 18, label: "Shaanxi", children: [{ id: 19, label: "Xi'an", }, { id: 20, label: "Yan'an", }, ], }, { id: 21, label: "Xinjiang Uyghur Autonomous Region", children: [{ id: 22, label: "Urumqi", }, { id: 23, label: "Karamay", }, ], }, ], }, ], multiIndex: [0, 0, 0], multiIds: [], newArr: [], }, bindMultiPickerChange(e) { console.log(this.data.multiIds); }, bindMultiPickerColumnChange(e) { let data = { newArr: this.data.newArr, multiIndex: this.data.multiIndex, multiIds: this.data.multiIds, }; data.multiIndex[e.detail.column] = e.detail.value; let searchColumn = () => { let arr1 = []; let arr2 = []; this.data.multiArray.map((v, vk) => { if (data.multiIndex[0] === vk) { data.multiIds[0] = { ...v, }; v.children.map((c, ck) => { arr1.push(c.label); if (data.multiIndex[1] === ck) { data.multiIds[1] = { ...c, }; c.children.map((t, vt) => { arr2.push(t.label); if (data.multiIndex[2] === vt) { data.multiIds[2] = { ...t, }; } }); } }); } }); data.newArr[1] = arr1; data.newArr[2] = arr2; }; switch (e.detail.column) { case 0: // Restore the initial value each time you switch data.multiIndex[1] = 0; data.multiIndex[2] = 0; //Execute function processing searchColumn(); break; case 1: data.multiIndex[2] = 0; searchColumn(); break; } this.setData(data); }, /** * Life cycle function--listen for page loading*/ onLoad: function (options) { let state = { arr: [], arr1: [], arr2: [], arr3: [], multiIds: [] } this.data.multiArray.map((v, vk) => { state.arr1.push(v.label); if (this.data.multiIndex[0] === vk) { state.multiIds[0] = v; } if (state.arr2.length <= 0) { v.children.map((c, ck) => { state.arr2.push(c.label); if (this.data.multiIndex[1] === ck) { state.multiIds[1] = c; } if (state.arr3.length <= 0) { c.children.map((t, tk) => { state.arr3.push(t.label); if (this.data.multiIndex[2] === tk) { state.multiIds[2] = t; } }); } }); } }); state.arr[0] = state.arr1; state.arr[1] = state.arr2; state.arr[2] = state.arr3; this.setData({ newArr: state.arr, multiIds: state.multiIds, }); }, /** * Life cycle function - listen for the completion of the initial rendering of the page*/ onReady: function () {}, /** * Life cycle function--monitor page display*/ onShow: function () {}, /** * Life cycle function--listen for page hiding*/ onHide: function () {}, /** * Life cycle function--monitor page uninstallation*/ onUnload: function () {}, /** * Page related event processing function - listen to user pull-down action */ onPullDownRefresh: function () {}, /** * The function that handles the bottoming event on the page*/ onReachBottom: function () {}, /** * User clicks on the upper right corner to share*/ onShareAppMessage: function () {}, }); This is the end of this article about WeChat mini program picker multi-column selector (mode = multiSelector). For more relevant mini program picker multi-column selector content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Why not use UTF-8 encoding in MySQL?
I recently used the input size and maxlength attri...
Preface Recently, I found a pitfall in upgrading ...
BackUpMysql.sh script #!/bin/bash PATH=/bin:/sbin...
Table of contents Causes of MySQL Table Fragmenta...
Today, I encountered a little problem when I was ...
Table of contents 1. Create a new project 2. Add ...
Currently, most CPUs support floating-point units...
Table of contents 1. Schematic diagram of group q...
This article records some major setting changes w...
When playing music, the lyrics will gradually fil...
Some common statements for viewing transactions a...
How to implement the "Set as homepage" ...
Table of contents 1. What does shallow copy mean?...
Table of contents Create a new user Authorize new...
After starting Docker, let's take a look at t...