微信小程序多列選擇器之range-key:html
<picker mode="multiSelector" bindchange="bindMultiPickerChange2" bindcolumnchange="bindMultiPickerColumnChange2" value="{{multiIndex}}" range="{{objectMultiArray}}" range-key="{{'name'}}"> <view class="picker"> 當前選擇:{{objectMultiArray[0][multiIndex2[0]].name}},{{objectMultiArray[1][multiIndex2[1]].name}} </view> </picker>
Page({ /** * 頁面的初始數據 */ data: { objectMultiArray: [ [ { id: 0, name: '無脊柱動物' }, { id: 1, name: '脊柱動物' } ], [ { id: 0, name: '扁性動物' }, { id: 1, name: '線形動物' }, { id: 2, name: '環節動物' }, { id: 3, name: '軟體動物' }, { id: 3, name: '節肢動物' } ] ], multiIndex2: [0, 0], }, bindMultiPickerChange2: function (e) { console.log('picker發送選擇改變,攜帶值爲', e.detail.value) this.setData({ multiIndex2: e.detail.value }) }, bindMultiPickerColumnChange2: function (e) { console.log('修改的列爲', e.detail.column, ',值爲', e.detail.value); var data = { objectMultiArray: this.data.objectMultiArray, multiIndex2: this.data.multiIndex2 }; data.multiIndex2[e.detail.column] = e.detail.value; switch (e.detail.column) { case 0: switch (data.multiIndex2[0]) { case 0: data.objectMultiArray[1] = [ { id: 0, name: '扁性動物' }, { id: 1, name: '線形動物' }, { id: 2, name: '環節動物' }, { id: 3, name: '軟體動物' }, { id: 3, name: '節肢動物' } ]; // data.multiArray[2] = ['豬肉絛蟲', '吸血蟲']; break; case 1: data.objectMultiArray[1] = [ { id: 0, name: '魚' }, { id: 1, name: '線形兩棲動物' }, { id: 2, name: '爬行動物' } ]; break; } data.multiIndex2[1] = 0; // data.multiIndex[2] = 0; break; } this.setData(data); } })
請記得點贊額!!!前端
|------components |------toast |------toast.js |------toast.wxml |------toast.wxss
|------components |------toast |------toast.js |------toast.wxml |------toast.wxss
<template name='toast'> <view class="s-toast" wx:if="{{msg}}"> <view class="s-toast-content">{{msg}}</view> </view> </template>
<template name='toast'> <view class="s-toast" wx:if="{{msg}}"> <view class="s-toast-content">{{msg}}</view> </view> </template>
/** * toastMsg 必傳 提示內容 * showTime 非必傳 顯示時間秒 */ function toast(page, toastMsg, showTime) { let timer page.setData({ toastMsg }) showTime = showTime || toastMsg.length / 4 console.log(showTime) clearTimeout(timer) timer = setTimeout(() => { page.setData({ toastMsg: '' }) clearTimeout(timer) }, showTime * 1000) } module.exports = { toast: toast, }
/** * toastMsg 必傳 提示內容 * showTime 非必傳 顯示時間秒 */ function toast(page, toastMsg, showTime) { let timer page.setData({ toastMsg }) showTime = showTime || toastMsg.length / 4 console.log(showTime) clearTimeout(timer) timer = setTimeout(() => { page.setData({ toastMsg: '' }) clearTimeout(timer) }, showTime * 1000) } module.exports = { toast: toast, }
.s-toast-content { position: fixed; left: 50%; color: #fff; width: 500rpx; bottom: 120rpx; background: hsla(0,0%,7%,.7); padding: 15rpx; text-align: center; -webkit-transform: translateX(-50%); transform: translateX(-50%); border-radius: 4rpx; z-index: 6999; }
.s-toast-content { position: fixed; left: 50%; color: #fff; width: 500rpx; bottom: 120rpx; background: hsla(0,0%,7%,.7); padding: 15rpx; text-align: center; -webkit-transform: translateX(-50%); transform: translateX(-50%); border-radius: 4rpx; z-index: 6999; }
import { toast } from '../../../project/component/toast/toast.js'
import { toast } from '../../../project/component/toast/toast.js'
toast(this, '填寫詳細信息')
toast(this, '填寫詳細信息')
toast(this,'填寫詳細信息'')
toast(this,'填寫詳細信息'')
變成vue
toast('填寫詳細信息'')
toast('填寫詳細信息'')