Represents a scrollable picker. It contains one or more scrollable lists, each displaying distinct values.
Since: 1.0.0
Name | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
mode | string | selector | No | Picker type.
|
disabled | boolean | false | No | Disabled or not. |
bindcancel | eventhandle | - | No | Event handler triggered when the selection is canceled. |
In addition to the preceding common properties, picker has different properties for different modes.
mode = selector: common picker
Property | Type | Default Value | Description |
|---|---|---|---|
range | array/object array | [] | Value range. Valid when mode is set to selector or multiSelector. |
range-key | string | - | Key in the object whose value is displayed in the picker. Valid when range is an object array. |
value | number | 0 | Index of the selected item within the range. The index is zero-based. |
bindchange | eventhandle | - | Event handler triggered when value changes, with event.detail = {value}. |
mode = multiSelector: multi-column picker
Property | Type | Default Value | Description |
|---|---|---|---|
range | array/object array | [] | Value range. Valid when mode is set to selector or multiSelector. |
range-key | string | - | Key in the object whose value is displayed in the picker. Valid when range is an object array. |
value | array | [] | Index of the selected item within the range. The index is zero-based. |
bindchange | eventhandle | - | Event handler triggered when value changes, with event.detail = {value}. |
bindcolumnchange | eventhandle | - | Event handler triggered when the column is changed. |
mode = time: time picker
Property | Type | Default Value | Description |
|---|---|---|---|
value | string | - | Selected time. Format: hh:mm. |
start | string | - | Start time of the valid time range. Format: hh:mm. |
end | string | - | End time of the valid time range. Format: hh:mm. |
bindchange | eventhandle | - | Event handler triggered when value changes, with event.detail = {value}. |
mode = date: date picker
Property | Type | Default Value | Description |
|---|---|---|---|
value | string | Current day | Selected date. Format: YYYY-MM-DD. |
start | string | - | Start date of the valid date range. Format: YYYY-MM-DD. |
end | string | - | End date of the valid date range. Format: YYYY-MM-DD. |
bindchange | eventhandle | - | Event handler triggered when value changes, with event.detail = {value}. |
mode = region: province/city/district picker
Property | Type | Default Value | Description |
|---|---|---|---|
value | array | [] | Selected province, city, and district. By default, the first value in each column is selected. |
bindchange | eventhandle | - | Event handler triggered when value changes, with event.detail = {value, code,}, where code indicates the administrative region code. |
HXML file:
<view class="page-body">
<view class="page-section">
<view class="contentTitle">Pokémon picker</view>
<view class="contentBody">
<view class="contentKey">Current selection</view>
<view class="contentVal">
<picker
bindchange="bindPickerChange"
value="{{index}}"
range="{{array}}">
<view>{{array[index]}}</view>
</picker>
</view>
</view>
<view class="contentTitle">Time picker</view>
<view class="contentBody">
<view class="contentKey">Current selection</view>
<view class="contentVal">
<picker
mode="time"
value="{{time}}"
start="09:01"
end="21:01"
bindchange="bindTimeChange">
<view>{{time}}</view>
</picker>
</view>
</view>
</view>
</view> JS file:
Page({
data: {
array: ['Pikachu', 'Charmander', 'Squirtle', 'Charmeleon'],
index: 0,
time: '12:01',
},
bindPickerChange(e) {
console.log('The picker sends a selection change event. Carried value: ', e.detail.value);
this.setData({
index: e.detail.value,
});
},
bindTimeChange(e) {
this.setData({
time: e.detail.value,
});
},
});