// pages/myCollection/myCollection.js Page({ /** * 页面的初始数据 */ data: { Collections:[], itemid:"", list:[] }, async getCollections(){ //调用云函数getCollection获取Collection表noteid[] this.setData({ list:[] }) wx.cloud.callFunction({ name:"getCollection" }).then(res=>{ let datas=res.result.data //根据noteid[]遍历,调用note数据库的get()把一条数据传给lists //将lists赋值list datas.forEach((element,index) => { wx.cloud.callFunction({ name:"getNotes", data:{ type:2, noteid:element.noteid, title:this.data.title } }).then(res=>{ this.setData({ list:this.data.list.concat(res.result.data[0]) }) }) }); this.setData({ Collections:datas, }) }) }, cancelCollection(e){ this.setData({ itemid:e.currentTarget.dataset.itemid }) wx.cloud.database().collection('Collection').where({noteid:this.data.itemid}).remove().then(res=>{ }).catch(res=>{ console.log("取消收藏失败",res) }) wx.cloud.callFunction({ name:"updatenote", data:{ type:2, itemid:this.data.itemid } }) this.getCollections() }, note: function (e) { if (e.currentTarget.dataset.type == 1) { wx.navigateTo({ url: '../chakan/chakan?id=' + e.currentTarget.dataset.id }) } else { wx.navigateTo({ url: '../chakan/chakan?id=' + e.currentTarget.dataset.id }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getCollections() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })