微信小程序多列选择器之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('填写详细信息'')