index.js 746 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. field: true,
  4. relation: {
  5. name: 'checkbox',
  6. type: 'descendant',
  7. current: 'checkbox-group',
  8. linked(target) {
  9. this.updateChild(target);
  10. },
  11. },
  12. props: {
  13. max: Number,
  14. value: {
  15. type: Array,
  16. observer: 'updateChildren',
  17. },
  18. disabled: {
  19. type: Boolean,
  20. observer: 'updateChildren',
  21. },
  22. },
  23. methods: {
  24. updateChildren() {
  25. (this.children || []).forEach((child) => this.updateChild(child));
  26. },
  27. updateChild(child) {
  28. const { value, disabled } = this.data;
  29. child.setData({
  30. value: value.indexOf(child.data.name) !== -1,
  31. parentDisabled: disabled,
  32. });
  33. },
  34. },
  35. });