Checkboxes 复选框

用于实现多选。

基本用法

```schema: scope=”body” { “type”: “form”, “api”: “/api/mock2/form/saveForm”, “body”: [ { “name”: “checkboxes”, “type”: “checkboxes”, “label”: “复选框”, “options”: [ { “label”: “OptionA”, “value”: “a” }, { “label”: “OptionB”, “value”: “b” }, { “label”: “OptionC”, “value”: “c” }, { “label”: “OptionD”, “value”: “d” } ] } ] }

  1. ## 显示全选
  2. 通过 `checkAll` 属性配置全选
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "api": "/api/mock2/form/saveForm",
  7. "body": [
  8. {
  9. "name": "checkboxes",
  10. "type": "checkboxes",
  11. "label": "复选框",
  12. "checkAll": true,
  13. "options": [
  14. {
  15. "label": "OptionA",
  16. "value": "a"
  17. },
  18. {
  19. "label": "OptionB",
  20. "value": "b"
  21. },
  22. {
  23. "label": "OptionC",
  24. "value": "c"
  25. },
  26. {
  27. "label": "OptionD",
  28. "value": "d"
  29. }
  30. ]
  31. }
  32. ]
  33. }

按钮模式

```schema: scope=”body” { “type”: “form”, “api”: “/api/mock2/form/saveForm”, “body”: [ { “name”: “checkboxes”, “type”: “checkboxes”, “label”: “复选框”, “optionType”: “button”, “options”: [ { “label”: “OptionA”, “value”: “a” }, { “label”: “OptionB”, “value”: “b” }, { “label”: “OptionC”, “value”: “c” }, { “label”: “OptionD”, “value”: “d” } ] } ] }

  1. ## 按列显示
  2. 设置 `"inline": false`
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "api": "/api/mock2/form/saveForm",
  7. "body": [
  8. {
  9. "name": "checkboxes",
  10. "type": "checkboxes",
  11. "label": "复选框",
  12. "inline": false,
  13. "options": [
  14. {
  15. "label": "OptionA",
  16. "value": "a"
  17. },
  18. {
  19. "label": "OptionB",
  20. "value": "b"
  21. },
  22. {
  23. "label": "OptionC",
  24. "value": "c"
  25. },
  26. {
  27. "label": "OptionD",
  28. "value": "d"
  29. }
  30. ]
  31. }
  32. ]
  33. }

展示多行

可以配置columnsCount属性调整展示列的个数

```schema: scope=”body” { “type”: “form”, “api”: “/api/mock2/form/saveForm”, “body”: [ { “name”: “checkboxes1”, “type”: “checkboxes”, “label”: “默认的复选框”, “options”: [ { “label”: “OptionA”, “value”: “a” }, { “label”: “OptionB”, “value”: “b” }, { “label”: “OptionC”, “value”: “c” }, { “label”: “OptionD”, “value”: “d” } ] }, { “type”: “divider” }, { “name”: “checkboxes2”, “type”: “checkboxes”, “label”: “显示两列的复选框”, “columnsCount”: 2, “inline”: false, “options”: [ { “label”: “OptionA”, “value”: “a” }, { “label”: “OptionB”, “value”: “b” }, { “label”: “OptionC”, “value”: “c” }, { “label”: “OptionD”, “value”: “d” } ] } ] }

  1. > 1.8.0 及以上版本
  2. `columnsCount` 还有一种数组形式,可以手动控制每行显示的列数
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "api": "/api/mock2/form/saveForm",
  7. "body": [
  8. {
  9. "name": "checkboxes1",
  10. "type": "checkboxes",
  11. "label": "默认的复选框",
  12. "columnsCount": [1, 2, 3],
  13. "options": [
  14. {
  15. "label": "OptionA",
  16. "value": "a"
  17. },
  18. {
  19. "label": "OptionB",
  20. "value": "b"
  21. },
  22. {
  23. "label": "OptionC",
  24. "value": "c"
  25. },
  26. {
  27. "label": "OptionD",
  28. "value": "d"
  29. },
  30. {
  31. "label": "OptionE",
  32. "value": "e"
  33. },
  34. {
  35. "label": "OptionF",
  36. "value": "f"
  37. }
  38. ]
  39. }
  40. ]
  41. }

分组显示

"inline": false 下,选项中配置 children 字段可以实现分组展示效果。

```schema: scope=”body” { “type”: “form”, “mode”: “horizontal”, “debug”: true, “body”: [ { “type”: “checkboxes”, “name”: “checkboxes”, “label”: “城市选择”, “inline”: false, “checkAll”: true, “options”: [ { “label”: “A类型”, “children”: [ { “label”: “选项 A-1”, “value”: “a-1” }, { “label”: “选项 A-2”, “value”: “a-2” } ] }, { “label”: “B类型”, “children”: [ { “label”: “选项 B-1”, “value”: “b-1” }, { “label”: “选项 B-2”, “value”: “b-2” }, { “label”: “选项 B-3”, “value”: “b-3” }, { “label”: “选项 B-4”, “value”: “b-4” } ] } ] } ] }

  1. ## 自定义选项渲染
  2. > 2.0.0 及以上版本
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "api": "/api/mock2/form/saveForm",
  7. "body": [
  8. {
  9. "name": "checkboxes",
  10. "type": "checkboxes",
  11. "label": "复选框",
  12. "menuTpl": "<span class='label label-${klass}'>${label}</span>",
  13. "options": [
  14. {
  15. "label": "OptionA",
  16. "value": "a",
  17. "klass": "success"
  18. },
  19. {
  20. "label": "OptionB",
  21. "value": "b",
  22. "klass": "danger"
  23. },
  24. {
  25. "label": "OptionC",
  26. "value": "c",
  27. "klass": "warning"
  28. },
  29. {
  30. "label": "OptionD",
  31. "value": "d",
  32. "klass": "info"
  33. }
  34. ]
  35. }
  36. ]
  37. }

属性表

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

属性名 类型 默认值 说明
options Array<object>Array<string> 选项组
source stringAPI 动态选项组
delimiter string , 拼接符
labelField string "label" 选项标签字段
valueField string "value" 选项值字段
joinValues boolean true 拼接值
extractValue boolean false 提取值
columnsCount number 1 选项按几列显示,默认为一列
menuTpl string 支持自定义选项渲染
checkAll boolean false 是否支持全选
inline boolean true 是否显示为一行
defaultCheckAll boolean false 默认是否全选
creatable boolean false 新增选项
createBtnLabel string "新增选项" 新增选项
addControls Array<表单项> 自定义新增表单项
addApi API 配置新增选项接口
editable boolean false 编辑选项
editControls Array<表单项> 自定义编辑表单项
editApi API 配置编辑选项接口
removable boolean false 删除选项
deleteApi API 配置删除选项接口

事件表

当前组件会对外派发以下事件,可以通过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 更新的值 更新数据,多个值用,分隔