基础库 1.0.0 开始支持,低版本需做兼容处理。

从底部弹起的滚动选择器。

属性 类型 默认值 必填 说明 最低版本
mode string selector 否 选择器类型 1.0.0
disabled boolean false 否 是否禁用 1.0.0
bindcancel eventhandle   否 取消选择时触发 1.9.90

mode 的合法值

值 说明 最低版本
selector 普通选择器  
multiSelector 多列选择器  
time 时间选择器  
date 日期选择器  
region 省市区选择器  

除了上述通用的属性,对于不同的mode,picker拥有不同的属性。

普通选择器:mode = selector

属性名 类型 默认值 说明 最低版本
range array/object array [] mode 为 selector 或 multiSelector 时,range 有效  
range-key string   当 range 是一个 Object Array 时,通过 range-key 来指定 Object 中 key 的值作为选择器显示内容  
value number 0 表示选择了 range 中的第几个(下标从 0 开始)  
bindchange eventhandle   value 改变时触发 change 事件,event.detail = {value}  

多列选择器:mode = multiSelector

属性名 类型 默认值 说明 最低版本
range array/object array [] mode 为 selector 或 multiSelector 时,range 有效  
range-key string   当 range 是一个 Object Array 时,通过 range-key 来指定 Object 中 key 的值作为选择器显示内容  
value array [] 表示选择了 range 中的第几个(下标从 0 开始)  
bindchange eventhandle   value 改变时触发 change 事件,event.detail = {value}  
bindcolumnchange eventhandle   列改变时触发  

时间选择器:mode = time

属性名 类型 默认值 说明 最低版本
value string   表示选中的时间,格式为"hh:mm"  
start string   表示有效时间范围的开始,字符串格式为"hh:mm"  
end string   表示有效时间范围的结束,字符串格式为"hh:mm"  
bindchange eventhandle   value 改变时触发 change 事件,event.detail = {value}  

日期选择器:mode = date

属性名 类型 默认值 说明 最低版本
value string 0 表示选中的日期,格式为"YYYY-MM-DD"  
start string   表示有效日期范围的开始,字符串格式为"YYYY-MM-DD"  
end string   表示有效日期范围的结束,字符串格式为"YYYY-MM-DD"  
fields string day 有效值 year,month,day,表示选择器的粒度  
bindchange eventhandle   value 改变时触发 change 事件,event.detail = {value}  

fields 有效值:*

值 说明
year 选择器粒度为年
month 选择器粒度为月份
day 选择器粒度为天

1.4.0

属性名 类型 默认值 说明 最低版本
value array [] 表示选中的省市区,默认选中每一列的第一个值  
custom-item string   可为每一列的顶部添加一个自定义的项 1.5.0
bindchange eventhandle   value 改变时触发 change 事件,event.detail = {value, code, postcode},其中字段 code 是统计用区划代码,postcode 是邮政编码  

示例代码

在开发者工具中预览效果

<view class="section">
  <view class="section__title">普通选择器</view>
  <picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}">
    <view class="picker">
      当前选择:{{array[index]}}
    </view>
  </picker>
</view>
<view class="section">
  <view class="section__title">多列选择器</view>
  <picker mode="multiSelector" bindchange="bindMultiPickerChange" bindcolumnchange="bindMultiPickerColumnChange" value="{{multiIndex}}" range="{{multiArray}}">
    <view class="picker">
      当前选择:{{multiArray[0][multiIndex[0]]}},{{multiArray[1][multiIndex[1]]}},{{multiArray[2][multiIndex[2]]}}
    </view>
  </picker>
</view>
<view class="section">
  <view class="section__title">时间选择器</view>
  <picker mode="time" value="{{time}}" start="09:01" end="21:01" bindchange="bindTimeChange">
    <view class="picker">
      当前选择: {{time}}
    </view>
  </picker>
</view>

<view class="section">
  <view class="section__title">日期选择器</view>
  <picker mode="date" value="{{date}}" start

相关文章:

  • 2021-11-30
  • 2021-05-07
  • 2021-08-24
  • 2021-11-21
  • 2021-08-10
  • 2023-03-18
  • 2021-11-21
  • 2021-11-21
猜你喜欢
  • 2021-11-21
  • 2021-11-21
  • 2021-09-20
  • 2021-12-07
  • 2021-07-24
  • 2022-12-23
相关资源
相似解决方案