index.js 1.0 KB

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