if (this.data.SellUpArray[buyind] == 0)//说明没点赞过 { var nowup = 'SellUpArray[' + buyind + ']'//设置为点赞过 this.setData({ [nowup]: 1 }) const db = wx.cloud.database({ env: 'gdouerhome-8gtde3z00e0425c7' }) return db.collection('Assistant_Sell_Intention').add({ //添加新数据到数据库 data: { buy_Post_id: e.currentTarget.dataset.buypost_id, buypostopenid: e.currentTarget.dataset.buypostopenid, Time_s: Date.now() }
时间: 2024-02-14 15:08:33 浏览: 23
这段代码实现了对交易市场中的帖子进行点赞的功能。首先判断该帖子是否已经点过赞,如果没有,则将该帖子对应的 `SellUpArray` 数组中的值设置为 1。然后通过 `wx.cloud.database` API 获取到数据库实例,调用 `collection` 函数获取到集合实例。接着调用 `add` 函数将新的点赞信息添加到集合中。其中 `buy_Post_id`、`buypostopenid` 和 `Time_s` 分别表示该帖子的 id、卖家的 openid 和点赞的时间戳。
相关问题
commit: function () { var url = getApp().globalData.baseUrl + getApp().globalData.url + getApp().globalData.addcomment; console.log(url+"=="+this.data.id+'==='+this.data.buid+"==="+this.data.zz);
这段代码看起来是一个提交评论的函数。它使用了小程序中的 getApp() 方法获取全局数据对象,然后拼接了评论接口的 URL,并将评论的相关参数作为 URL 参数进行了提交。其中,this.data.id 表示评论的对象 ID,this.data.buid 表示评论者的 ID,this.data.zz 表示评论的内容。最后,通过 console.log() 输出了拼接好的 URL,用于调试和验证。
upclickbutton: function (e) { var that = this var ind = e.currentTarget.dataset.nowindex console.log("Post_id:" + e.currentTarget.dataset.post_id) const postuserid = e.currentTarget.dataset.postopenid console.log(this.data.UpArray) console.log(this.data.UpArray[ind] == 0) if (this.data.UpArray[ind] == 0)//说明没点赞过 { var nowup = 'UpArray[' + ind + ']'//设置为点赞过 this.setData({ [nowup]: 1 }) const db = wx.cloud.database({ env: 'gdouerhome-8gtde3z00e0425c7' }) return db.collection('Assistant_Up').add({ //添加帖子 data: { Up_Post_id: e.currentTarget.dataset.post_id, Up_id: e.currentTarget.dataset.postopenid, Time_s: Date.now() } }).then(res => { console.log("Assistant_Up OK!"); console.log("Pick the post_id:" + e.currentTarget.dataset.post_id);
这段代码实现了对帖子进行点赞的功能。首先判断该帖子是否已经点过赞,如果没有,则将该帖子对应的 `UpArray` 数组中的值设置为 1。然后通过 `wx.cloud.database` API 获取到数据库实例,调用 `collection` 函数获取到集合实例。接着调用 `add` 函数将新的点赞信息添加到集合中。其中 `Up_Post_id`、`Up_id` 和 `Time_s` 分别表示该帖子的 id、点赞者的 openid 和点赞的时间戳。当添加数据成功时,会在 `then` 函数中执行回调函数,输出提示信息和帖子的 id。