index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var component_1 = require("../common/component");
  4. component_1.VantComponent({
  5. field: true,
  6. relation: {
  7. name: 'checkbox',
  8. type: 'descendant',
  9. linked: function (target) {
  10. this.children = this.children || [];
  11. this.children.push(target);
  12. this.updateChild(target);
  13. },
  14. unlinked: function (target) {
  15. this.children = this.children.filter(function (child) { return child !== target; });
  16. }
  17. },
  18. props: {
  19. max: Number,
  20. value: {
  21. type: Array,
  22. observer: 'updateChildren'
  23. },
  24. disabled: {
  25. type: Boolean,
  26. observer: 'updateChildren'
  27. }
  28. },
  29. methods: {
  30. updateChildren: function () {
  31. var _this = this;
  32. (this.children || []).forEach(function (child) {
  33. return _this.updateChild(child);
  34. });
  35. },
  36. updateChild: function (child) {
  37. var _a = this.data, value = _a.value, disabled = _a.disabled;
  38. child.set({
  39. value: value.indexOf(child.data.name) !== -1,
  40. disabled: disabled || child.data.disabled
  41. });
  42. }
  43. }
  44. });