Checkbox 勾选框

用于实现勾选,功能和 Switch 类似,只是展现上不同。

基本用法

```schema: scope=”body” { “type”: “form”, “body”: [ { “name”: “checkbox”, “type”: “checkbox”, “label”: “勾选框”, “option”: “选项说明” } ] }

  1. ## 配置真假值
  2. 默认情况:
  3. - 勾选框勾选时,表单项值为:true
  4. - 勾选框取消勾选时,表单项值为:false
  5. ```schema: scope="body"
  6. {
  7. "type": "form",
  8. "debug": true,
  9. "body": [
  10. {
  11. "name": "checkbox",
  12. "type": "checkbox",
  13. "label": "勾选框",
  14. "option": "选项说明"
  15. }
  16. ]
  17. }

如果你想调整这个值,可以配置trueValuefalseValue

```schema: scope=”body” { “type”: “form”, “debug”: true, “body”: [ { “name”: “checkbox”, “type”: “checkbox”, “label”: “勾选框”, “option”: “选项说明”, “trueValue”: 1, “falseValue”: 0 } ] }

  1. 勾选上例中的勾选框,观察数据域变化,会发现勾选后值为`1`,而取消勾选后为`0`
  2. ## 按钮模式
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "debug": true,
  7. "body": [
  8. {
  9. "name": "checkbox",
  10. "type": "checkbox",
  11. "label": "勾选框",
  12. "trueValue": true,
  13. "falseValue": false,
  14. "optionType": "button",
  15. "option": "选项说明"
  16. }
  17. ]
  18. }

属性表

除了支持 普通表单项属性表 中的配置以外,还支持下面一些配置

属性名 类型 默认值 说明
option string 选项说明
trueValue string|number|boolean true 标识真值
falseValue string|number|boolean false 标识假值
optionType default|button default 设置 option 类型

事件表

当前组件会对外派发以下事件,可以通过onEvent来监听这些事件,并通过actions来配置执行的动作,在actions中可以通过event.data.xxx事件参数变量来获取事件产生的数据,详细请查看事件动作

事件名称 事件参数 说明
change event.data.value: boolean 选中状态 选中状态变化时触发

动作表

当前组件对外暴露以下特性动作,其他组件可以通过指定actionType: 动作名称componentId: 该组件id来触发这些动作,动作配置可以通过args: {动作配置项名称: xxx}来配置具体的参数,详细请查看事件动作

动作名称 动作配置 说明
clear - 清空
reset - 将值重置为resetValue,若没有配置resetValue,则清空
setValue `value: string \ number \ boolean` 更新的值 更新数据