my.optionsselect(object object)
主体: 企业支付宝小程序 、 个人支付宝小程序
唤起 select 选择器。
二级联动需求请使用 my.multilevelselect。
object object
查看示例
属性 | 类型 | 默认值 | 必填 | 描述 |
---|---|---|---|---|
title | string | - | 否 | 头部标题信息 |
optionsone | array |
- | 是 | 选项一列表 |
optionstwo | array |
- | 否 | 选项二列表 |
selectedoneindex | number | 0 | 否 | 选项一默认选中的值 |
selectedtwoindex | number | 0 | 否 | 选项二默认选中的值 |
positivestring | string | 确定 | 否 | 确定按钮文案 |
negativestring | string | 取消 | 否 | 取消按钮文案 |
success | function | - | 否 | 调用成功的回调函数 |
fail | function | - | 否 | 调用失败的回调函数 |
complete | function | - | 否 | 调用结束的回调函数(调用成功、失败都会执行) |
success 回调函数
参数
object res
查看示例
属性 | 类型 | 描述 |
---|---|---|
selectedoneindex | number | 选项一选择的值,若选择取消,则返回空字符串 |
selectedtwoindex | number | 选项一选择的内容,若选择取消,则返回空字符串 |
selectedoneoption | string | 选项二选择的值,若选择取消,则返回空字符串 |
selectedtwooption | string | 选项二选择的内容,若选择取消,则返回空字符串 |
fail 回调的参数为 object,error
属性为错误码,errormessage
属性为错误消息。
错误码 | 错误消息 | 凯发app官方网站的解决方案 |
---|---|---|
2 | xxx 不能为空 | 请检查 xxx 字段,不能为空 |
xxx 参数类型错误 | 请检查入参 xxx,传入正确的类型。 |
在线示例
代码示例
扫码体验
my.optionsselect(object object)
引用 json 文件作为选项列表参数数据
success 参数
//唤起单列选择器
my.optionsselect({
title: "还款日选择",
optionsone: ["每周一", "每周二", "每周三", "每周四", "每周五", "每周六", "每周日"],
selectedoneindex: 2,
success: function (res) {
console.log(res);
},
fail: function (err) {
console.log(err);
}
});
//唤起双列选择器
my.optionsselect({
title: "出生年月选择",
optionsone: ["2014年", "2013年", "2012年", "2011年", "2010年", "2009年", "2008年"],
optionstwo: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
selectedoneindex: 3,
selectedtwoindex: 5,
success: function (res) {
console.log(res);
},
fail: function (err) {
console.log(err);
}
});
const fs = my.getfilesystemmanager();
fs.readfile({
filepath: '/pages/test.json',
encoding: 'utf-8',
success: function (res) {
const json = json.parse(res.data);
console.log(json)
my.optionsselect({
title: "还款日选择",
optionsone: json.year,
selectedoneindex: 2,
success: function (res) {
console.log(res);
},
fail: function (err) {
console.log(err);
}
});
},
fail: function (err) {
console.log(err);
},
})
//单列数据
{
"selectedoneindex": 2,
"selectedoneoption": "每周三"
}
//双列数据
{
"selectedoneindex": 3,
"selectedoneoption": "2011年",
"selectedtwoindex": 5,
"selectedtwooption": "六月"
}
q:如何引用 json 文件作为选项列表参数数据?
a:
可以先通过 filesystemmanager.readfile 读取 json 文件内容,然后再调用 my.optionsselect。查看 参考代码。