微信小程序云开发sum求和,count,in查询,分页,模糊查询
分类: 微信小程序 专栏: 小程序 标签: 微信小程序云开发sum求和,count,in查询
2024-11-04 11:42:22 191浏览
微信小程序云开发sum求和,count,in查询
const db = wx.cloud.database() const _ = db.command; const $ = db.command.aggregate; getAllList() { let that=this; let query={ tb: true, status: Number(1) }; if(that.data.xxlx.length>0)query.xxlx=_.in(that.data.xxlx);//in查询 if(that.data.value!='')query.content= wx.cloud.database().RegExp({ regexp: this.data.value, options: 'i' })//模糊cha'xu if(that.data.isload){ that.setData({loadtext:'数据加载中...'}) return; } if(that.data.pageNo==1){ that.setData({allList:[],tempali:[]}); that.getAllListCount(query); that.getAllListSum(query); } let pageStart=(that.data.pageNo-1)*that.data.pageSize; db.collection('actions').where(query).skip( pageStart).limit(that.data.pageSize) .orderBy('zd2', 'desc').orderBy('time', 'desc').get() .then(res => { console.log(res) let li=res.data; if(li.length==0){ that.setData({ loadtext:'暂无数据',isload:false}) return; } that.setData({tempali:li,loadtext:'上拉加载更多数据',isload:false}) if(li.length<that.data.pageSize){ that.setData({ loadtext:'暂无数据'}) } }) }, getAllListCount(query){ let that=this; //计算总条数 that.setData({total:0}) db.collection('actions').where(query).count().then(res=>{ console.log("count=",res) let total=res.total; that.setData({total:total}) }) }, getAllListSum(query){ let that=this; //计算总浏览量 that.setData({ sumNum:0 }) db.collection('actions').aggregate().match(query).group({ _id: null, sum: $.sum('$liulanNum') }).end().then(res=>{ if(res.list.length>0){ let sum=parseInt(res.list[0].sum); that.setData({ sumNum:sum }) } }) },
好博客就要一起分享哦!分享海报
此处可发布评论
评论(0)展开评论
暂无评论,快来写一下吧
展开评论
他的专栏
他感兴趣的技术