myLikeMessage.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. Component({
  2. data: {
  3. newNews: []
  4. },
  5. lifetimes: {
  6. ready: function() {
  7. wx.showLoading({
  8. title: "加载中",
  9. })
  10. const db = wx.cloud.database()
  11. db.collection("likeData").where({
  12. type: "message"
  13. }).get({
  14. success: function (res) {
  15. if (res.data.length == 0) {
  16. wx.hideLoading()
  17. return
  18. }
  19. this.processData(res.data)
  20. }.bind(this)
  21. })
  22. }
  23. },
  24. methods: {
  25. processData: function (arr) {
  26. const db = wx.cloud.database()
  27. for (let i = 0; i < arr.length; i++) {
  28. db.collection("mainData").doc(arr[i].id).get({
  29. success: function (res) {
  30. arr[i].publisherAvatar = res.data.publisherAvatar
  31. arr[i].publisherName = res.data.publisherName
  32. arr[i].title = res.data.title
  33. arr[i].subTitle = res.data.subTitle
  34. this.setData({
  35. newNews: arr
  36. })
  37. wx.hideLoading()
  38. }.bind(this)
  39. })
  40. }
  41. }
  42. }
  43. })