# Select(下拉选择)
# 使用范围
ui、行为、规则组件通用
# 使用方式
config:{
grade: {
text: '年级',
type: 'Select',
options: [
{
text: '一年级',
value: '1'
},
{
text: '二年级',
value: '2'
},
{
text: '三年级',
value: '3'
},
{
text: '四年级',
value: '4'
},
{
text: '五年级',
value: '5'
},
{
text: '六年级',
value: '6'
}
]
}
}
- 高阶版 异步获取options数据 和 级联
config:{
grade: {
text: '年级(接口返回)',
type: 'Select',
async options(ctx) {
const res = await ctx.get('https://www.fastmock.site/mock/283e63f48717b24b99d74775cbc5ec25/editor/getGrades')
if (res.code === 0) {
return res.data.list
} else {
return []
}
}
},
courseId: {
text: '课程id(级联,根据年级变化而变化)',
type: 'Select',
cascade: 'grade',
async options(ctx, parent) {
if (parent === '3') {
return [
{
text: '3年级数学',
value: '1'
},
{
text: '3年级英语',
value: '2'
}
]
} else {
return [
{
text: '其他年级数学',
value: '3'
}
]
}
}
}
}
# 特有参数
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 是否必填 |
|---|---|---|---|---|---|
| options | 选项内容(对象数组或者function return 对象数组, 返回参数parent 当设置cascade时返回) | boolean | array object / function(ctx, parent) | false | 是 |
| cascade | 级联,父级config key | string | * | * | 否 |
# 效果
