You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

  1. //index.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. propArray: {
  8. type: Array,
  9. }
  10. },
  11. /**
  12. * 组件的初始数据
  13. */
  14. data: {
  15. selectShow: false,//初始option不显示
  16. selectText: "请选择",//初始内容
  17. },
  18. /**
  19. * 组件的方法列表
  20. */
  21. methods: {
  22. //option的显示与否
  23. selectToggle: function () {
  24. var nowShow = this.data.selectShow;//获取当前option显示的状态
  25. this.setData({
  26. selectShow: !nowShow
  27. })
  28. },
  29. //设置内容
  30. setText: function (e) {
  31. var nowData = this.properties.propArray;//当前option的数据是引入组件的页面传过来的,所以这里获取数据只有通过this.properties
  32. var nowIdx = e.target.dataset.index;//当前点击的索引
  33. var nowText = nowData[nowIdx].text || nowData[nowIdx].value || nowData[nowIdx];//当前点击的内容
  34. //再次执行动画,注意这里一定,一定,一定是this.animation来使用动画
  35. this.setData({
  36. selectShow: false,
  37. selectText: nowText,
  38. })
  39. this.triggerEvent('select', nowData[nowIdx])
  40. }
  41. }
  42. })