success: function (res) { console.log("Buy_Post OK!"); that.get_Sell_DBinf() wx.showToast({ title: '已加入意向购买', image: '../../images/Up_heart.png', duration: 2000 }) }, fail: err => { console.log('error:', err) } }) }) } else { wx.showToast({ title: '你已经点过了哦!', image: '../../images/buy.png', duration: 2000 }) } },
时间: 2024-02-10 19:08:55 浏览: 175
这代码是在 `add` 函数中的 `success` 回调函数中执行的。当添加数据成功时,会调用 `get_Sell_DBinf` 函数重新加载交易市场的数据。同时通过 `wx.showToast` API 显示一个提示框,提示用户已经成功加入意向购买。当用户已经点过赞时,则弹出提示框提示用户已经点过了。
相关问题
这段代码有什么问题吗,为什么点赞信息不会更新到帖子?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[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); wx.cloud.callFunction({ name: 'Up_Assistant_Post', data: { Post_id: e.currentTarget.dataset.post_id, }, success: function (res) { console.log("Up_Assistant_Post OK!"); that.get_DBinf() wx.showToast({ title: '已点赞', image: '../../images/Up_heart.png', duration: 2000 }) }, fail: err => { console.log('error:', err) } }) }) } else{ wx.showToast({ title: '已点赞过', image: '../../images/Up_heart2.png', duration: 2000 }) }
这段代码没有明显的语法错误,但是点赞信息不会更新到帖子可能是因为以下原因:
1. 检查 UpArray 数组是否正确设置了初始值,如果没有设置初始值,那么第一次点赞时 UpArray[ind] 将会是 undefined,导致判断出错。
2. 确认数据库操作是否成功,可以在控制台输出添加点赞信息的结果 res,查看是否有错误信息。
3. 检查云函数 Up_Assistant_Post 是否正确实现了更新帖子的功能,可以在云函数中添加日志输出,查看是否有错误信息。
4. 确认页面数据是否正确渲染,可以在 get_DBinf() 函数中添加日志输出,查看数据是否正确获取到了。
综上所述,可以加入更多的日志输出来定位问题所在。
success: function (res) { if (res.data.code == 0) { console.log(res.data.data) that.setData({ datalist: res.data.data }) } else { wx.showToast({ title: res.data.msg, icon: 'non
这是一个小程序中的 JavaScript 代码,其中包含了一个名为 `success` 的回调函数。当小程序从服务器成功获取数据时,如果返回的数据中 `code` 等于 0,则将数据保存到 `datalist` 中,并利用 `setData` 方法更新页面数据。如果 `code` 不等于 0,则显示一个提示框,内容为返回数据中的 `msg`。其中 `console.log` 用于在控制台输出数据,方便开发者调试。
阅读全文
相关推荐
















