searchbar.js 780 B

1234567891011121314151617181920212223242526272829303132
  1. Page({
  2. data: {
  3. inputShowed: false,
  4. inputVal: "",
  5. i: 0
  6. },
  7. onLoad() {
  8. this.setData({
  9. search: this.search.bind(this)
  10. })
  11. },
  12. search: function (value) {
  13. return new Promise((resolve, reject) => {
  14. if (this.data.i % 2 === 0) {
  15. setTimeout(() => {
  16. resolve([{text: '搜索结果', value: 1}, {text: '搜索结果2', value: 2}])
  17. }, 200)
  18. } else {
  19. setTimeout(() => {
  20. resolve([])
  21. }, 200)
  22. }
  23. this.setData({
  24. i: this.data.i + 1
  25. })
  26. })
  27. },
  28. selectResult: function (e) {
  29. console.log('select result', e.detail)
  30. },
  31. });