HomeDocs
Skip to main content

picker

Introduction

A scroll picker that pops up from the bottom.

Property Description

PropertyTypeDefaultRequiredDescriptionMinimum Version
cancel-textstringCancelNoText for the cancel button of the picker3.2.0
confirm-textstringConfirmNoText for the confirm button of the picker3.2.0
modestringselectorNoPicker type; valid values: selector, multiSelector, time, date3.2.0
disabledbooleanfalseNoWhether the picker is disabled3.2.0
bindcanceleventhandleNoTriggered when canceling the selection or clicking outside the picker3.2.0
confirm-closebooleantrueNoWhether the picker should close when the confirm button is clicked, default is to close3.2.0
confirm-text-colorstring#0081FFNoColor of the confirm button3.2.0
cancel-text-colorstring#61656DNoColor of the cancel button3.2.0
title-colorstring#191f2bNoColor of the title text3.2.0
selected-text-colorstring#191f2bNoColor of the selected item text3.2.0

Valid Values for the "mode" Property

ValueDescriptionMinimum Version
selectorNormal selector3.2.0
multiSelectorMulti-column selector3.2.0
timeTime selector3.3.0
dateDate selector3.3.0

In addition to the common properties mentioned above, picker has different properties for different modes.

Normal Selector (mode = selector)

PropertyTypeDefaultDescriptionMinimum Version
rangearray/object array[]The range is valid when the mode is selector or multiSelector3.2.0
range-keystringWhen range is an Object Array, this specifies the key in the Object to display as the selector content3.2.0
valuenumber0Represents the index of the selected item in the range (starting from 0)3.2.0
bindchangeeventhandleTriggered when the value changes (when the confirm button is clicked), event.detail = {value: value}3.2.0
header-textstringTitle of the picker3.2.0

Multi-column Selector (mode = multiSelector)

PropertyTypeDefaultDescriptionMinimum Version
rangearray/object array[]The range is valid when the mode is selector or multiSelector3.2.0
range-keystringWhen range is an Object Array, this specifies the key in the Object to display as the selector content3.2.0
valuearray[]Represents the index of the selected item in each column (starting from 0)3.2.0
bindcolumnchangeeventhandleTriggered when the value of a column changes, event.detail = {column: column, value: value}, where column is the column index (starting from 0) and value is the index of the changed value3.2.0
header-textstringTitle of the picker3.2.0

Time Selector (mode = time)

PropertyTypeDefaultDescriptionMinimum Version
valuestringRepresents the selected time in hh:mm format3.3.0
startstringRepresents the start of the valid time range in hh:mm format3.3.0
endstringRepresents the end of the valid time range in hh:mm format3.3.0
bindchangeeventhandleTriggered when the value changes (when the confirm button is clicked), event.detail = {value: value}3.3.0

Date Selector (mode = date)

PropertyTypeDefaultDescriptionMinimum Version
valuestringCurrent dateRepresents the selected date, default format is DD/MM/YYYY, Chinese and Arabic formats: YYYY/MM/DD3.3.0
startstringRepresents the start of the valid date range, default string format is DD/MM/YYYY, Chinese and Arabic formats: YYYY/MM/DD3.3.0
endstringRepresents the end of the valid date range, default string format is DD/MM/YYYY, Chinese and Arabic formats: YYYY/MM/DD3.3.0
fieldsstringdayValid values are year, month, day, representing the granularity of the selector3.3.0
bindchangeeventhandleTriggered when the value changes (when the confirm button is clicked), event.detail = {value: value}3.3.0

Valid Values for "fields":

ValueDescription
yearSelector granularity is year
monthSelector granularity is month
daySelector granularity is day

Sample Code

<view class="section">
<view class="section__title">Normal Selector</view>
<picker bindchange="bindPickerChange" :value="index" :range="array">
<view class="picker"> Current Selection: {{array[index]}} </view>
</picker>
</view>
<view class="section">
<view class="section__title">Multi-column Selector</view>
<picker
mode="multiSelector"
bindchange="bindMultiPickerChange"
bind

columnchange="bindMultiPickerColumnChange"
:value="multiIndex"
:range="multiArray"
>
<view class="picker">
Current Selection: {{multiArray[0][multiIndex[0]]}}, {{multiArray[1][multiIndex[1]]}}, {{multiArray[2][multiIndex[2]]}}
</view>
</picker>
</view>
<view class="section">
<view class="section__title">Time Selector</view>
<picker
mode="time"
:value="time"
start="09:01"
end="21:01"
bindchange="bindTimeChange"
>
<view class="picker"> Current Selection: {{time}} </view>
</picker>
</view>

<view class="section">
<view class="section__title">Date Selector</view>
<picker
mode="date"
:value="date"
start="2015-09-01"
end="2017-09-01"
bindchange="bindDateChange"
>
<view class="picker"> Current Selection: {{date}} </view>
</picker>
</view>
Page({
data: {
array: ["USA", "China", "Brazil", "Japan"],
objectArray: [
{
id: 0,
name: "USA",
},
{
id: 1,
name: "China",
},
{
id: 2,
name: "Brazil",
},
{
id: 3,
name: "Japan",
},
],
index: 0,
multiArray: [
["Invertebrate", "Vertebrate"],
["Flatworm", "Roundworm", "Annelid", "Mollusk", "Arthropod"],
["Tapeworm", "Leech"],
],
objectMultiArray: [
[
{
id: 0,
name: "Invertebrate",
},
{
id: 1,
name: "Vertebrate",
},
],
[
{
id: 0,
name: "Flatworm",
},
{
id: 1,
name: "Roundworm",
},
{
id: 2,
name: "Annelid",
},
{
id: 3,
name: "Mollusk",
},
{
id: 3,
name: "Arthropod",
},
],
[
{
id: 0,
name: "Tapeworm",
},
{
id: 1,
name: "Leech",
},
],
],
multiIndex: [0, 0, 0],
date: "2016-09-01",
time: "12:01",
},
bindPickerChange: function (e) {
console.log("Picker sent selection change, value:", e.detail.value);
this.setData({
index: e.detail.value,
});
},
bindMultiPickerChange: function (e) {
console.log("Picker sent selection change, value:", e.detail.value);
this.setData({
multiIndex: e.detail.value,
});
},
bindMultiPickerColumnChange: function (e) {
console.log("Changed column:", e.detail.column, ", value:", e.detail.value);
var data = {
multiArray: this.data.multiArray,
multiIndex: this.data.multiIndex,
};
data.multiIndex[e.detail.column] = e.detail.value;
switch (e.detail.column) {
case 0:
switch (data.multiIndex[0]) {
case 0:
data.multiArray[1] = [
"Flatworm",
"Roundworm",
"Annelid",
"Mollusk",
"Arthropod",
];
data.multiArray[2] = ["Tapeworm", "Leech"];
break;
case 1:
data.multiArray[1] = ["Fish", "Amphibian", "Reptile"];
data.multiArray[2] = ["Carp", "Mackerel"];
break;
}
data.multiIndex[1] = 0;
data.multiIndex[2] = 0;
break;
case 1:
switch (data.multiIndex[0]) {
case 0:
switch (data.multiIndex[1]) {
case 0:
data.multiArray[2] = ["Tapeworm", "Leech"];
break;
case 1:
data.multiArray[2] = ["Ascaris"];
break;
case 2:
data.multiArray[2] = ["Ant", "Leech"];
break;
case 3:
data.multiArray[2] = ["Clam", "Snail", "Slug"];
break;
case 4:
data.multiArray[2] = [
"Insect",
"Crustacean",
"Arachnid",
"Myriapod",
];
break;
}
break;
case 1:
switch (data.multiIndex[1]) {
case 0:
data.multiArray[2] = ["Carp", "Mackerel"];
break;
case 1:
data.multiArray[2] = ["Frog", "Guppy"];
break;
case 2:
data.multiArray[2] = ["Lizard", "Turtle", "Gecko"];
break;
}
break;
}
data.multiIndex[2] = 0;
break;
}
console.log(data.multiIndex);
this.setData(data);
},

bindDateChange: function (e) {
console.log("Picker sent selection change, value:", e.detail.value);
this.setData({
date: e.detail.value,
});
},
bindTimeChange: function (e) {
console.log("Picker sent selection change, value:", e.detail.value);
this.setData({
time: e.detail.value,
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.