index.js 724 B

12345678910111213141516171819202122232425262728293031
  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. },
  19. methods: {
  20. updateChildren() {
  21. this.children.forEach((child) => this.updateChild(child));
  22. },
  23. updateChild(child) {
  24. const { value, disabled } = this.data;
  25. child.setData({
  26. value: value.indexOf(child.data.name) !== -1,
  27. parentDisabled: disabled,
  28. });
  29. },
  30. },
  31. });