Checkbox 复选

概述

基本组件-多选框。主要用于一组可选项多项选择,或者单独用于标记切换某种状态。

使用指南

在 .json 中引入组件

  1. "usingComponents": {
  2. "i-checkbox-group": "../../dist/checkbox-group/index",
  3. "i-checkbox": "../../dist/checkbox/index"
  4. }

示例

  1. <i-panel title="group-水果">
  2. <i-checkbox-group current="{{current}}" bindchange="handleFruitChange">
  3. <i-checkbox wx:for="{{fruit}}" position="{{position}}" wx:key="{{item.id}}" value="{{item.name}}">
  4. </i-checkbox>
  5. </i-checkbox-group>
  6. </i-panel>
  7. <i-button bindclick="handleClick" type="ghost">切换复选框位置</i-button>
  8. <i-panel title="checkbox-动物">
  9. <i-checkbox value="{{animal}}" disabled="{{disabled}}" checked="{{checked}}" bindchange="handleAnimalChange">
  10. </i-checkbox>
  11. </i-panel>
  12. <i-button bindclick="handleDisabled" type="ghost">切换disabled状态</i-button>
  1. Page({
  2. data: {
  3. fruit: [{
  4. id: 1,
  5. name: '香蕉',
  6. }, {
  7. id: 2,
  8. name: '苹果'
  9. }, {
  10. id: 3,
  11. name: '西瓜'
  12. }, {
  13. id: 4,
  14. name: '葡萄',
  15. }],
  16. current: ['苹果', '葡萄'],
  17. position: 'left',
  18. animal: '熊猫',
  19. checked: false,
  20. disabled: false,
  21. },
  22. handleFruitChange({ detail = {} }) {
  23. const index = this.data.current.indexOf(detail.value);
  24. index === -1 ? this.data.current.push(detail.value) : this.data.current.splice(index, 1);
  25. this.setData({
  26. current: this.data.current
  27. });
  28. },
  29. handleClick() {
  30. this.setData({
  31. position: this.data.position.indexOf('left') !== -1 ? 'right' : 'left',
  32. });
  33. },
  34. handleDisabled() {
  35. this.setData({
  36. disabled: !this.data.disabled
  37. });
  38. },
  39. handleAnimalChange({ detail = {} }) {
  40. this.setData({
  41. checked: detail.current
  42. });
  43. },
  44. });

API

CheckboxGroup properties

属性说明类型默认值
i-class自定义 class 类名String-
current指定当前选中的项目 valueArray[]

CheckboxGroup events

事件名说明返回值
bind:change切换选项时触发current

CheckboxGroup properties

属性说明类型默认值
i-class自定义 class 类名String-
value当前项的 valueString-
checked当前项是否选中Booleanfalse
disabled是否禁用当前项Booleanfalse
color主题色String-
position位置,可选值为 left 或 rightStringleft

CheckboxGroup events

事件名说明返回值
bind:change切换选项时触发current