这段代码有什么问题吗,为什么点赞信息不会更新到帖子?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 }) }
时间: 2023-06-27 15:06:08 浏览: 187
这段代码没有明显的语法错误,但是点赞信息不会更新到帖子可能是因为以下原因:
1. 检查 UpArray 数组是否正确设置了初始值,如果没有设置初始值,那么第一次点赞时 UpArray[ind] 将会是 undefined,导致判断出错。
2. 确认数据库操作是否成功,可以在控制台输出添加点赞信息的结果 res,查看是否有错误信息。
3. 检查云函数 Up_Assistant_Post 是否正确实现了更新帖子的功能,可以在云函数中添加日志输出,查看是否有错误信息。
4. 确认页面数据是否正确渲染,可以在 get_DBinf() 函数中添加日志输出,查看数据是否正确获取到了。
综上所述,可以加入更多的日志输出来定位问题所在。
相关问题
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。
o="layui-carousel-left",r="layui-carousel-right",d="layui-carousel-prev",s="layui-carousel-next",u="layui-carousel-arrow",c="layui-carousel-ind",m=function(e){var t=this;t.config=i.extend({},t
这是一段 JavaScript 代码,其中包含了一个函数 m,用于实现轮播图的功能。这个函数接受一个参数 e,用于配置轮播图的相关参数。具体来说,它首先使用 extend 方法从默认参数中继承配置参数。接着,它定义了一些常量,包括表示轮播图左右箭头的类名、表示轮播图上一张图片的类名、表示轮播图下一张图片的类名、表示轮播图箭头的类名、表示轮播图指示器的类名等。然后,它定义了一个变量 t,表示函数 m 的上下文对象。接下来,它定义了一些方法,包括 getELEM、getIndex、doArrow、doPlay 等,用于获取元素、获取当前索引、实现箭头点击事件、实现轮播等功能。最后,它将这些方法和一些属性绑定到 t 上,并返回 t。
阅读全文
相关推荐
















