本篇內(nèi)容主要講解“微信小程序picker多列選擇器怎么用”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“微信小程序picker多列選擇器怎么用”吧!
在海曙等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計(jì)制作、成都做網(wǎng)站 網(wǎng)站設(shè)計(jì)制作定制網(wǎng)站設(shè)計(jì),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),全網(wǎng)營銷推廣,成都外貿(mào)網(wǎng)站建設(shè)公司,海曙網(wǎng)站建設(shè)費(fèi)用合理。
vue-next-admin,這是基于 vue3.x + CompositionAPI + typescript + vite + element plus + vue-router-next + next.vuex,適配手機(jī)、平板、pc 的后臺(tái)開源免費(fèi)模板庫
文檔地址:微信開發(fā)文檔 picker選擇器
普通選擇器:mode = selector,一維數(shù)組:array: ["美國", "中國", "巴西", "日本"]
多列選擇器:mode = multiSelector,二維數(shù)組:multiArray: [["無脊柱動(dòng)物", "脊柱動(dòng)物"], ["扁性動(dòng)物", "線形動(dòng)物", "環(huán)節(jié)動(dòng)物", "軟體動(dòng)物", "節(jié)肢動(dòng)物"], ["豬肉絳蟲", "吸血蟲"]]
格式不對(duì),要處理成對(duì)應(yīng)數(shù)組格式,占坑圖:
{ "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" } }
<!--pages/picker/picker.wxml--> <view> <view class="section__title">多列選擇器</view> <picker mode="multiSelector" bindchange="bindMultiPickerChange" bindcolumnchange="bindMultiPickerColumnChange" value="{{multiIndex}}" range="{{newArr}}"> <view class="picker"> 當(dāng)前選擇: <van-button type="primary"> {{newArr[0][multiIndex[0]]}},{{newArr[1][multiIndex[1]]}},{{newArr[2][multiIndex[2]]}}</van-button> </view> </picker> </view>
多列選擇器:mode = multiSelector
注意看數(shù)組格式:multiArray數(shù)組
有 children
,要處理二維數(shù)組:
// pages/picker/picker.js Page({ /** * 頁面的初始數(shù)據(jù) */ data: { multiArray: [{ id: 1, label: "東南", children: [{ id: 2, label: "上海", children: [{ id: 3, label: "普陀", }, { id: 4, label: "黃埔", }, { id: 5, label: "徐匯", }, ], }, { id: 7, label: "江蘇", children: [{ id: 8, label: "南京", }, { id: 9, label: "蘇州", }, { id: 10, label: "無錫", }, ], }, { id: 12, label: "浙江", children: [{ id: 13, label: "杭州", }, { id: 14, label: "寧波", }, { id: 15, label: "嘉興", }, ], }, ], }, { id: 17, label: "西北", children: [{ id: 18, label: "陜西", children: [{ id: 19, label: "西安", }, { id: 20, label: "延安", }, ], }, { id: 21, label: "新疆維吾爾族自治區(qū)", children: [{ id: 22, label: "烏魯木齊", }, { id: 23, label: "克拉瑪依", }, ], }, ], }, ], 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: // 每次切換還原初始值 data.multiIndex[1] = 0; data.multiIndex[2] = 0; // 執(zhí)行函數(shù)處理 searchColumn(); break; case 1: data.multiIndex[2] = 0; searchColumn(); break; } this.setData(data); }, /** * 生命周期函數(shù)--監(jiān)聽頁面加載 */ 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, }); }, /** * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成 */ onReady: function () {}, /** * 生命周期函數(shù)--監(jiān)聽頁面顯示 */ onShow: function () {}, /** * 生命周期函數(shù)--監(jiān)聽頁面隱藏 */ onHide: function () {}, /** * 生命周期函數(shù)--監(jiān)聽頁面卸載 */ onUnload: function () {}, /** * 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作 */ onPullDownRefresh: function () {}, /** * 頁面上拉觸底事件的處理函數(shù) */ onReachBottom: function () {}, /** * 用戶點(diǎn)擊右上角分享 */ onShareAppMessage: function () {}, });
到此,相信大家對(duì)“微信小程序picker多列選擇器怎么用”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
新聞名稱:微信小程序picker多列選擇器怎么用
本文網(wǎng)址:http://aaarwkj.com/article14/ipdsge.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、品牌網(wǎng)站制作、關(guān)鍵詞優(yōu)化、定制網(wǎng)站、網(wǎng)站導(dǎo)航、網(wǎng)頁設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)