index.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. field: true,
  4. relation: {
  5. name: 'checkbox',
  6. type: 'descendant',
  7. linked: function linked(target) {
  8. var _this$data = this.data,
  9. value = _this$data.value,
  10. disabled = _this$data.disabled;
  11. target.set({
  12. value: value.indexOf(target.data.name) !== -1,
  13. disabled: disabled || target.data.disabled
  14. });
  15. }
  16. },
  17. props: {
  18. max: Number,
  19. value: Array,
  20. disabled: Boolean
  21. },
  22. watch: {
  23. value: function value(_value) {
  24. var children = this.getRelationNodes('../checkbox/index');
  25. children.forEach(function (child) {
  26. child.set({
  27. value: _value.indexOf(child.data.name) !== -1
  28. });
  29. });
  30. },
  31. disabled: function disabled(_disabled) {
  32. var children = this.getRelationNodes('../checkbox/index');
  33. children.forEach(function (child) {
  34. child.set({
  35. disabled: _disabled || child.data.disabled
  36. });
  37. });
  38. }
  39. }
  40. });