index.js 969B

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