- 多账号和真机调试,返回数据库里没有的数据?
这里是想实现聊天功能,所以有一个ChatOnline集合来保存用户是否在线 ChatOnline集合里只有一条数据,user1是1813100并且user2是18121300的数据 [图片] 当我用开发工具登录18131000的账号,用多账号测试或者真机登录18121300账号的时候,18131000退出时返回正常,但18121300用户退出时数据库查询函数查出的数据如图,和实际数据库的内容不符 [图片] onUnload: function () { var that = this const uid = wx.getStorageSync('uid') const info = wx.getStorageSync('info') db.collection('ChatOnline') //更新自己的在线状态 .where(db.command.or([ { user1:info.id, user2:uid, }, { user1:uid, user2:info.id }, ])) .get() .then(res=>{ console.log(res.data) //这里返回的数据错误 if(res.data[0].user1=info.id) { console.log("use1") db.collection('ChatOnline') //更新自己的状态 .where({ user1:info.id, user2:uid }).update({ data:{ user1online:false } }).then(res=>{ console.log('退出') }) } else{ console.log("use2") db.collection('ChatOnline') //更新自己的状态 .where({ user2:info.id, user1:uid }).update({ data:{ user2online:false } }).then(res=>{ console.log('退出') }) } }) } [图片]
2022-05-19 - 求教如何把这个for循环变成同步?
尝试了用promise,但输出编号发现还是异步执行 for(let i =0;i<res.data.length;i++) { var id = res.data[i].uid; new Promise((resolve, reject) => { console.log(id) db.collection('Student') .where({ _id:id }).get() .then(res=>{ if(res.data.length==0) { db.collection('Teacher') .where({ _id:id }).get() .then(res=>{ that.data.headlist.push(res.data[0].pic) that.setData({ headlist:that.data.headlist, }) setTimeout(function () { console.log(i) resolve() }, 500) }).catch(res=>{ console.log(res) }) } else { that.data.headlist.push(res.data[0].pic) that.setData({ headlist:that.data.headlist, }) setTimeout(function () { console.log(i) resolve() }, 500) } }) }) } [图片]
2022-05-18 - 如何用云触发器定期删除指定记录?
我想实现封禁到时间自动解除的功能,day是封禁天数,time是封禁时的时间戳 我在云函数里写了触发器并上传了,但没有起作用,日志里没看到调用记录 记录判断条件的正确写法该怎么写? const cloud = require('wx-server-sdk') cloud.init() const db = cloud.database(); // 云函数入口函数 exports.main = async (event, context) => { const wxContext = cloud.getWXContext() var nowtime = Date.parse(new Date())/1000; //当前时间 const $ = db.command.aggregate; return await db.collection('Blocked') .aggregate() .project({ matched:$.gt([nowtime,'$time'+'$day'*24*3600]), time:1, day:1, }) .match({ matched:true }) .end() .remove() } [图片]
2022-05-15 - 怎么保存wx.cloud.downloadFile下载得到的视频文件?
wx.openDocument不支持视频后缀的样子,该用什么保存?
2022-05-14 - 如果要查找云数据库数据集A里字段a=“1”或者字段b=“2”的记录该怎么写where?
如题
2022-05-13 - 如何让方框们靠右?
<view wx:for="{{chatlist}}" wx:for-item="item" > <view wx:if="{{item.type=='text'}}" style="display: flex;position: relative;"> <view class="self"> <text>{{item.content}}</text> </view> <image src="../../image/righttr.png" style="width: 40rpx;" mode="widthFix"></image> </view> </view> .self{ background-color:rgb(36,80,134); color: white; border-radius: 7%; width: auto; right: 20rpx; min-height: 50rpx; margin-bottom: 20rpx; padding-left: 20rpx; padding-right: 30rpx; padding-top: 10rpx; padding-bottom: 10rpx; word-break: break-all; } [图片]
2022-05-12 - 怎样监听云数据库的数据变化实现并实时显示在页面中?(聊天功能)
如题,想实现聊天功能,但该如何有新数据时实时刷新页面呢?
2022-05-11 - 怎样实现微信云数据库的条件“或”查询?
比如说我要查询集合col里,要想筛选出a、b字段符合(a=1&&b=2) ||(a=2&&b=1)的记录该怎么查?
2022-05-10 - 利用promise该如何实现同步?
想实现同步,getData调用getathead,getathead又调用gethead,但出现promise未定义的报错,请问正确该怎么写 onLoad: function (options) { this.getData(); }, async getData(){ var that= this var id = wx.getStorageSync('info').id db.collection('Notice') .where({ message:"@", noticed:id }).get() .then(res=>{ that.setData({ atlist:res.data }) that.getathead(); }) }, async getathead(){ var p = this.data.atlist; return new promise((reslove,reject)=>{ for(let i =0;i<p.length;i++) { this.gethead(p.uid); } reslove() }) }, gethead(id){ var list=this.data.headlist; return new promise((reslove,reject)=>{ db.collection('Student') .where({ _id:id }).get() .then(res=>{ if(res.data.length==0) { db.collection('Teacher') .where({ _id:id }).get() .then(res=>{ list.push(res.data[0].pic) this.setData({ headlist:list, }) reslove() }) } else { list.push(res.data[0].pic) this.setData({ headlist:list, }) reslove() } }) }) }, [图片]
2022-05-10 - 如何解决渲染和数据加载异步问题?
这里我想调用getgood函数将数据保存到goodlist中,再显示到页面中,但在加载完毕前已经渲染完了,不显示已经加载的数据,如何解决? onLoad: function (options) { this.getData(); this.getpos(); }, getpos(){ var c= wx.getStorageSync('com'); var that = this; db.collection('Post').where({ //获取全部贴文 major:c, }).orderBy('time','desc').get() .then(res=>{ that.setData({ postlist:res.data }) that.getgood().then(res=>{ console.log(res) }) }) .catch(err=>{ console.log("无法获取",err) }) }, getgood(){ var poslist = this.data.postlist; var list = []; var id = wx.getStorageSync('info').id var that = this; return new Promise((resolve, reject) => { for(let i =0;i<poslist.length;i++) { db.collection('Good') .where({ pid:poslist[i]._id, uid:id, }) .get() .then(res=>{ if(res.data.length==0) { list.push(false) } else list.push(true) }) if(i+1==poslist.length) { that.setData({ goodlist:list }) resolve(list); } } }) }, [图片]
2022-05-09