index.js 971 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. Component({
  2. externalClasses: ['i-class'],
  3. relations: {
  4. '../checkbox/index': {
  5. type: 'child',
  6. linked() {
  7. this.changeCurrent();
  8. },
  9. linkChanged() {
  10. this.changeCurrent();
  11. },
  12. unlinked() {
  13. this.changeCurrent();
  14. }
  15. }
  16. },
  17. properties: {
  18. current: {
  19. type: Array,
  20. value: [],
  21. observer: 'changeCurrent'
  22. },
  23. },
  24. methods: {
  25. changeCurrent(val = this.data.current) {
  26. let items = this.getRelationNodes('../checkbox/index');
  27. const len = items.length;
  28. if (len > 0) {
  29. items.forEach(item => {
  30. item.changeCurrent(val.indexOf(item.data.value) !== -1);
  31. });
  32. }
  33. },
  34. emitEvent(current) {
  35. this.triggerEvent('change', current);
  36. }
  37. }
  38. });