城市选择器 region
//index.wxml
<picker mode="region" bindchange="bindRegionChange" value="{{region}}">
<view class="picker">
当前选择:{{region[0]}},{{region[1]}},{{region[2]}}
view>
picker>
//index.js
data: {
region: ['广东省', '广州市', '海珠区']
}
多列选择器 multiSelector
脑残没有关注官方更新,自己写了个城市选择器。
// City.js
// 省份
var provinceList = [
{ "id": "11", "name": "北京", "initial": "B" },
...];
var cityList = [
{
"provinceId": "11",
"citys": [
{ "id": "1", "name": "昌平" },
...]
}
];
// 点击省份,获取城市列表
function getCitysById(id) {
let provinceId = provinceList[id].id;
var tempObj = [];
for (let i = 0; i < cityList.length; i++) {
if (cityList[i].provinceId == provinceId) {
tempObj = cityList[i].citys;
break;
}
}
return tempObj;
}
module.exports = {
provinceList: provinceList,
getCitysById: getCitysById
}
// Picker.wxml
<picker mode="multiSelector" value="{{index}}" bindcolumnchange="bindPickerChange" range="{{province}}" range-key="{{'name'}}">
<view class="picker">
当前选择:{{province[0][0].name}}{{province[1][0].name}}
view>
picker>
// Picker.js
var cityObj = require("../../utils/city")
Page({
data: {
index: 0
},
onLoad: function (options) {
var defaultCitys = cityObj.getCitysById("0")
this.setData({
province: [cityObj.provinceList, defaultCitys]
})
},
bindPickerChange(e) {
if (e.detail.column == 0) {
var citys = cityObj.getCitysById(e.detail.value);
this.setData({
province: [cityObj.provinceList, citys]
})
}
}
})
时间选择器 time
<picker mode="time" value="{{time}}" start="09:01" end="21:01" bindchange="bindTimeChange">
<view class="picker">
当前选择: {{time}}
view>
picker>
日期选择器 date
<picker mode="date" value="{{time}}" start="2015-09-01" end="2017-09-01" fields="month" bindchange="bindTimeChange">
<view class="picker">
当前选择: {{time}}
view>
picker>