Radios 单选框
用于实现单选。
基本用法
```schema: scope=”body” { “type”: “form”, “body”: [ { “name”: “radios”, “type”: “radios”, “label”: “radios”, “options”: [ { “label”: “OptionA”, “value”: “a” }, { “label”: “OptionB”, “value”: “b” }, { “label”: “OptionC”, “value”: “c” }, { “label”: “OptionD”, “value”: “d” } ] } ] }
## 列显示设置 `inline` 可以纵向显示,用于显示列很多的情况```schema: scope="body"{"type": "form","body": [{"name": "radios","type": "radios","label": "radios","inline": false,"options": [{"label": "OptionA","value": "a"},{"label": "OptionB","value": "b"},{"label": "OptionC","value": "c"},{"label": "OptionD","value": "d"}]}]}
控制列显示的分裂
通过 columnsCount 来设置列显示的列数,比如下面例子是两列。
```schema: scope=”body” { “type”: “form”, “body”: [ { “name”: “radios”, “type”: “radios”, “label”: “radios”, “inline”: false, “columnsCount”: 2, “options”: [ { “label”: “OptionA”, “value”: “a” }, { “label”: “OptionB”, “value”: “b” }, { “label”: “OptionC”, “value”: “c” }, { “label”: “OptionD”, “value”: “d” } ] } ] }
## 默认选择第一个通过 `selectFirst` 属性配置```schema: scope="body"{"type": "form","body": [{"name": "radios","type": "radios","label": "radios","selectFirst": true,"options": [{"label": "OptionA","value": "a"},{"label": "OptionB","value": "b"},{"label": "OptionC","value": "c"},{"label": "OptionD","value": "d"}]}]}
动态选项
可以配置 source 来从上下文或远程 api 拉取选项数据
```schema: scope=”body” { “type”: “page”, “body”: { “type”: “form”, “data”: { “items”: [ { “label”: “A”, “value”: “a” }, { “label”: “B”, “value”: “b” }, { “label”: “C”, “value”: “c” } ] }, “body”: [ { “label”: “选项”, “type”: “radios”, “name”: “radios”, “source”: “${items}” } ] } }
远程 api```schema: scope="body"{"type": "page","body": {"type": "form","body": [{"label": "选项","type": "radios","name": "radios","source": "/api/mock2/form/getOptions?waitSeconds=1"}]}}
api 返回内容需要包含 options 字段
{"status": 0,"msg": "","data": {"value": "b", // 可选,如果返回就会自动选中 b 选项// 必须用 options 作为选项组的 key 值"options": [{"label": "A","value": "a"},{"label": "B","value": "b"},{"label": "C","value": "c"}]}}
属性表
当做选择器表单项使用时,除了支持 普通表单项属性表 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| options | Array<object>或Array<string> |
选项组 | |
| source | string或 API |
动态选项组 | |
| labelField | boolean |
"label" |
选项标签字段 |
| valueField | boolean |
"value" |
选项值字段 |
| columnsCount | number |
1 |
选项按几列显示,默认为一列 |
| inline | boolean |
true |
是否显示为一行 |
| selectFirst | boolean |
false |
是否默认选中第一个 |
| autoFill | object |
自动填充 |
事件表
当前组件会对外派发以下事件,可以通过onEvent来监听这些事件,并通过actions来配置执行的动作,在actions中可以通过event.data.xxx事件参数变量来获取事件产生的数据,详细请查看事件动作。
| 事件名称 | 事件参数 | 说明 |
|---|---|---|
| change | event.data.value: string 选中值 |
选中值变化时触发 |
动作表
当前组件对外暴露以下特性动作,其他组件可以通过指定actionType: 动作名称、componentId: 该组件id来触发这些动作,动作配置可以通过args: {动作配置项名称: xxx}来配置具体的参数,详细请查看事件动作。
| 动作名称 | 动作配置 | 说明 |
|---|---|---|
| clear | - | 清空 |
| reset | - | 将值重置为resetValue,若没有配置resetValue,则清空 |
| reload | - | 重新加载,调用 source,刷新数据域数据刷新(重新加载) |
| setValue | value: string 更新的值 |
更新数据 |
