picker

以下为 picker 相关的 API,用于数据选择,日期选择,时间选择。

API

pick

pick(options, callback[options])

  • @options

    • index1 {number}: 默认选中的选项
    • index2 {number}: 默认选中的选项,无则填-1
    • index3 {number}: 默认选中的选项,无则填-1
    • items1 {array}: picker 数据源
    • items2 {array}: picker 数据源,可选
    • items3 {array}: picker 数据源,可选
    • title {string}: 对话框的标题
  • @callback,执行完读取操作后的回调函数 ret {Object}callback '函数的参数,有两个属性

    • result {string}: 结果三种类型 success, cancel, error
    • data1 {number}: 选择的选项,仅成功确认时候存在
    • data2 {number}: 选择的选项,仅成功确认时候存在
    • data3 {number}: 选择的选项,仅成功确认时候存在
const picker = weex.requireModule('picker');

const items1 = ['广东', '湖南', '广西'];
const items2 = [
    ['广州', '佛山', '东莞', '珠海'],
    ['长沙', '岳阳', '株洲', '衡阳'],
    ['桂林', '玉林']
];
const items3 = [
    [
        ['白云区', '从化区', '海珠区', '花都区', '黄埔区', '荔湾区', '番禺区'],
        ['高明区', '南海区', '三水区', '顺德区'],
        ['茶山镇', '长安镇', '常平镇'],
        ['香洲区', '斗门区', '金湾区', '其它区']
    ],
    [
        ['芙蓉区', '开福区', '天心区', '雨花区', '岳麓区', '望城区', '长沙县'],
        ['君山区', '华容县', '岳阳楼区', '云溪区'],
        ['荷塘区', '芦淞区', '石峰区', '天元区', '株洲县'],
        ['石鼓区', '雁峰区', '蒸湘区', '珠晖区', '南岳区']
    ],
    [
        ['叠彩区', '临桂区', '七星区', '象山区', '秀峰区'],
        ['福绵区', '玉州区', '容县']
    ],
];

picker.pick({
    index1: this.index1,
    index2: this.index2,
    index3: this.index3,
    items1: items1,
    items2: items2,
    items3: items3,
    title: "Picker Title"
}, event => {
    if (event.result === 'success') {
        this.index1 = event.data1;
        this.index2 = event.data2;
        this.index3 = event.data3;
    }
});

pickDate

pickDate(options, callback[options])

  • @options
    • title {string}: 对话框的标题
    • value {string}: 必选,date picker 选中的值,date 的字符串格式为 yyyy-MM-dd
    • max {string}: 可选,date 的最大值
    • min {string}: 可选,date 的最小值
  • @callback,执行完读取操作后的回调函数。ret {Object}callback 函数的参数,有两个属性:
    • result {string}: 结果三种类型 success, cancel, error
    • data {string}: 选择的值 date 的字符,格式为 yyyy-MM-dd, 仅成功确认的时候存在
const picker = weex.requireModule('picker');
picker.pickDate({
    value: "2017-01-22",
    max: '2029-11-28',
    min: '2005-11-28',
    title: "Picker Title"
}, event => {
    if (event.result === 'success') {
        this.value = event.data
    }
});

pickTime

pickTime(options, callback[options])

  • @options
    • title {string}: 对话框的标题
    • value {string}:必选,time 格式为 HH:mm:ss
  • @callback,执行完读取操作后的回调函数。ret {Object}callback 函数的参数,有两个属性
    • result {string}: 结果三种类型 success, cancel, error
    • data {string}:time 格式为 HH:mm:ss, 仅成功确认的时候存在
const picker = weex.requireModule('picker');
picker.pickTime({
    value: "09:30:01",
    title: "Picker Title"
}, event => {
    if (event.result === 'success') {
        this.value = event.data
    }
});

Demo