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” } ] } ] }

  1. ## 列显示
  2. 设置 `inline` 可以纵向显示,用于显示列很多的情况
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "body": [
  7. {
  8. "name": "radios",
  9. "type": "radios",
  10. "label": "radios",
  11. "inline": false,
  12. "options": [
  13. {
  14. "label": "OptionA",
  15. "value": "a"
  16. },
  17. {
  18. "label": "OptionB",
  19. "value": "b"
  20. },
  21. {
  22. "label": "OptionC",
  23. "value": "c"
  24. },
  25. {
  26. "label": "OptionD",
  27. "value": "d"
  28. }
  29. ]
  30. }
  31. ]
  32. }

控制列显示的分裂

通过 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” } ] } ] }

  1. ## 默认选择第一个
  2. 通过 `selectFirst` 属性配置
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "body": [
  7. {
  8. "name": "radios",
  9. "type": "radios",
  10. "label": "radios",
  11. "selectFirst": true,
  12. "options": [
  13. {
  14. "label": "OptionA",
  15. "value": "a"
  16. },
  17. {
  18. "label": "OptionB",
  19. "value": "b"
  20. },
  21. {
  22. "label": "OptionC",
  23. "value": "c"
  24. },
  25. {
  26. "label": "OptionD",
  27. "value": "d"
  28. }
  29. ]
  30. }
  31. ]
  32. }

动态选项

可以配置 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}” } ] } }

  1. 远程 api
  2. ```schema: scope="body"
  3. {
  4. "type": "page",
  5. "body": {
  6. "type": "form",
  7. "body": [
  8. {
  9. "label": "选项",
  10. "type": "radios",
  11. "name": "radios",
  12. "source": "/api/mock2/form/getOptions?waitSeconds=1"
  13. }
  14. ]
  15. }
  16. }

api 返回内容需要包含 options 字段

  1. {
  2. "status": 0,
  3. "msg": "",
  4. "data": {
  5. "value": "b", // 可选,如果返回就会自动选中 b 选项
  6. // 必须用 options 作为选项组的 key
  7. "options": [
  8. {
  9. "label": "A",
  10. "value": "a"
  11. },
  12. {
  13. "label": "B",
  14. "value": "b"
  15. },
  16. {
  17. "label": "C",
  18. "value": "c"
  19. }
  20. ]
  21. }
  22. }

属性表

当做选择器表单项使用时,除了支持 普通表单项属性表 中的配置以外,还支持下面一些配置

属性名 类型 默认值 说明
options Array<object>Array<string> 选项组
source stringAPI 动态选项组
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 更新的值 更新数据