- 如何到时间自动取消置顶?
实现效果:当置顶后,需要按着置顶的时长,自动取消置顶。 如图:当置顶时长到了之后自动删除topping字段,以达到自动取消置顶的效果,自己写了一段代码,能够实现自动删除这个字段,但是当所有数据中都没有topping这个字段后就会报错。哪位大师提供一个更好的实现案例学习下 [图片] [图片] 代码: // 取消置顶 async timer(){ await app.loadUserInfo(); let openid = await app.globalData.userInfo._openid; const toppings = await db.collection("wehicle").where({ _openid: openid }).get() if(toppings){ const wehicles = toppings.data; console.log(wehicles); wehicles.forEach((wehicle, index) => { const id = wehicle._id; console.log(id); if(wehicle.topping.timelength){ setTimeout(function(){ db.collection("wehicle").doc(id).update({ data:{ "topping":_.remove() } }) },wehicle.topping.timelength*1000*60) } }) } },
10-08 - 更新数据库字段后,更新页面显示问题?
如图:想要实现的效果,当点击了弹窗的确定按钮后更新数据库字段,在页面及时显示“顶”这个字,在代码中设置0:const wehicle = that.data.wehicles[0],就能够实现效果,如果设置为id,const wehicle = that.data.wehicles[id],就实现不了。这个id,是点击置顶按钮时的id值,这是什么原因呢? [图片] /** * 置顶弹窗 */ showCode(event) { console.log(event); const id = event.currentTarget.dataset.id console.log(id) this.setData({ show_input: true, id: id }) }, // 获取input输入框 getCodeValue(e) { this.setData({ code: e.detail.value, }) }, // 关闭弹窗 closeModal(e) { console.log(e); this.setData({ show_input: false }) }, // 点击确定 async confirm(e) { const that = this; const itmelength = that.data.code; const id = that.data.id; // 点击弹窗按钮的id, const wehicle = that.data.wehicles[0]; // 传入0能够实现效果,当传入id时,就不能实现。 console.log(wehicle) wx.showLoading({ title: "正在置顶中..." }) wx.cloud.callFunction({ name: "topping", data: { id: id, itmelength: itmelength, }, success: res => { console.log(res); const updated = res.result.stats.updated; if(!wehicle.topping){ wehicle.topping = [itmelength] }else{ wehicle.topping.push(itmelength) } const wehicles = that.data.wehicles; console.log(wehicles) wehicles[id] = wehicle console.log(wehicles[id]); that.setData({ wehicles:wehicles }) if (updated) { wx.hideLoading(); wx.showToast({ title: "恭喜!置顶成功!", }) setTimeout(function () { that.setData({ show_input: false, }) }, 800) } else { wx.showToast({ title: "置顶失败,请重新置顶!", }) } } }) },
09-26 - 更新数据库字段,怎么更新不了?
如图:当点击确定后,更新数据库,在数据库增加一个字段,在JS中能够成功添加,当在云函数中实现时,添加不了 [图片] 在这段代码中,能够成功添加: confirm(e){ const that = this; console.log(e); const itmelength = that.data.code; const id = that.data.id; const wehicles = that.data.wehicles; db.collection("wehicle").doc(id).update({ data:{ top:{ itmelength:itmelength, pud_data:new Date(), } } }) .then(res => { console.log(res); }) }, 在云函数中添加不了: // 云函数入口函数 exports.main = async (event, context) => { const wxContext = cloud.getWXContext(); const openid = wxContext.OPENID; const itmelength = event.itmelength; const id = event.id; console.log(id); return await db.collection("wehicle").doc(id).update({ data:{ "top":_.push({ itmelength:itmelength, pud_data:new Date(), }) } }) } js代码: confirm(e){ const that = this; console.log(e); const itmelength = that.data.code; const id = that.data.id; const wehicles = that.data.wehicles; wx.cloud.callFunction({ name:'topping', data:{ top:{ itmelength:itmelength, } }, success:res => { console.log(res); } }) }
09-23 - url的type怎么传?
如图中点击跳转到详情页,url中的type值怎么传? [图片][图片] <segment-carpool items="{{items}}" result="{{result}}" resultthree="{{result3}}" resultfous="{{result4}}" binditemchengde="onItemChengdeEvent" defaultIndex="0"> <view slot="0" class="segment-page wehicle-page"> </view> <view slot="1" class="segment-page people-page"> <view wx:if="{{isQuerying == true}}"> <view class="comment-title">全部信息(共有{{result1}}条)</view> <sumlistone wx:for="{{listones}}" wx:key="key" wx:for-item="listone" list1="{{listone}}"></sumlistone> </view> <view wx:else> <view class="comment-title">全部信息(共有{{result1}}条)</view> <wehicle wx:for="{{listones}}" wx:key="key" wx:for-item="listone" list1="{{listone}}" items="items.item" detailurl="../detail/detail?type={{itemchengde.items}}&index={{index}}"></wehicle> </view> </view> <view slot="2" class="segment-page train-page"> </view> <view slot="3" class="segment-page money-page"> </view> <view slot="4" class="segment-page money-page"> </view> </segment-carpool> <loadingmore hasmore="{{hasmore}}"></loadingmore> JS代码 data: { items: ["全部", "我要找车", "我要找人", "我找货车", "我要找货"], }, onItemChengdeEvent(event) { console.log(event) const that = this; var index = event.detail.index; that.setData({ index:index }) },
09-08 - 当点击查询清空input输入框,上拉加载更多失效?
如图,当点击查询后清空输入框的值,但是上拉加载更多时失效,获取不到数据,这个要怎么做? [图片] WXML代码: <form bindsubmit="formSubmit"> <view class="search-input-group"> <view class="input-group"> <input class="search-input" placeholder="出发地" value="{{startPoint}}" bindinput="onStartPointEvent" /> <image class="thumbnail" src="../../images/return.png" /> <input class="search-input" placeholder="终点" value="{{goal}}" bindinput="onGoalEvent" /> </view> <button class="search-button" size="mini" formType="submit">查询</button> </view> </form> JS代码: data: { hasmore: true, sumlistress:[], startPoint:'', goal: '', isQuerying: false, }, /** * 获取起点输入信息 */ onStartPointEvent(event) { const that = this; const startPoint = event.detail.value console.log('起点', startPoint); that.setData({ startPoint: startPoint }) }, /** * 获取终点输入信息 */ onGoalEvent(event) { const that = this; const goal = event.detail.value console.log('终点', goal); that.setData({ goal: goal }) }, /** * 按条件查询数据 */ async formSubmit(start = 0) { const that = this; that.setData({ isQuerying: true, }) let promite = db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, }) if(start>0){ promite = promite.skip(start) } let pro = await promite.limit(2).orderBy('create_time','desc').get() console.log(pro) if(pro){ const sumlistress = pro.data; console.log(sumlistress); promite.count().then(res => { console.log(res) that.setData({ result:res.total }) }) let hasmore = false let newsumlistress = []; if (start > 0) { newsumlistress = that.data.sumlistress.concat(sumlistress); } else { newsumlistress = sumlistress; } newsumlistress.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ sumlistress: newsumlistress, hasmore: hasmore, startPoint:'', goal: '' }) } }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { let hasmore = true; if(this.data.wehicles.length == 0 && this.data.sumlistress.length == 0){ hasmore = false } this.setData({ hasmore:hasmore }) if(!this.data.isQuerying) { this.lowdrelease(this.data.wehicles.length); }else{ this.formSubmit(this.data.sumlistress.length); } },
09-02 - 当只有一条或者没有数据的情况时,一直显示正在加载中?
当只有一条或者没有数据的情况下,一直显示正在加载中,如果全部项下拉加载出数据后,才会显示没有更多如图1。再就是当下拉加载时,第二次下拉时显示的没有更多数据,而不是显示正在加载中如图2。好像是和其他项有冲突。这个问题怎么解决? 图片:[图片][图片] 代码: <!--components/loadingmore/loadingmore.wxml--> <button class="loading-btn" loading="{{hasmore}}" style="height:{{height}}px;"> <block wx:if="{{hasmore}}"> <text class="loadingtext">{{loadingtext}}</text> </block> <block wx:else> <text class="loadingtext">{{loadedtext}}</text> </block> </button> index.wxml代码: <segment-carpool items="{{items}}" result="{{result}}" resultthree="{{result3}}" resultfous="{{result4}}" binditemchengde="onItemChengdeEvent" defaultIndex="0" > <view slot="0" class="segment-page wehicle-page"> <view class="comment-title">全部信息(共有{{result}}条)</view> <whole wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></whole> </view> <view slot="1" class="segment-page people-page"> <view class="comment-title">全部信息(共有{{result1}}条)</view> <wehicle wx:for="{{listones}}" wx:key="key" wx:for-item="listone" list1="{{listone}}"></wehicle> </view> <view slot="2" class="segment-page train-page"> <view class="comment-title">全部信息(共有{{result2}}条)</view> <people wx:if="{{listtwos}}" wx:for="{{listtwos}}" wx:key="key" wx:for-item="listtwo" list2="{{listtwo}}"></people> </view> <view slot="3" class="segment-page money-page"> <view class="comment-title">全部信息(共有{{result3}}条)</view> <train wx:for="{{listthrees}}" wx:key="key" wx:for-item="listthree" list3="{{listthree}}"></train> </view> <view slot="4" class="segment-page money-page" > <view class="comment-title">全部信息(共有{{result4}}条)</view> <money wx:for="{{listfours}}" wx:key="key" wx:for-item="listfour" list4="{{listfour}}"></money> </view> </segment-carpool> <loadingmore hasmore="{{hasmore}}"></loadingmore> index.jd代码: const db = wx.cloud.database(); Page({ /** * 页面的初始数据 */ data: { items: ["全部", "我要找车", "我要找人", "我找货车", "我要找货"], hasmore: true, wehicles: [], result: 0, result1: 0, result2: 0, result3: 0, result4: 0, startPoint:'', goal: '', isQuerying: false, list:[], listones:[], listtwos:[], listthrees:[], listfours:[], }, /** * 获取起点输入信息 */ onStartPointEvent(event) { const that = this; const startPoint = event.detail.value console.log('起点', startPoint); that.setData({ startPoint: startPoint }) }, /** * 获取终点输入信息 */ onGoalEvent(event) { const that = this; const goal = event.detail.value console.log('终点', goal); that.setData({ goal: goal }) }, /** * 按条件查询数据 */ formSubmit(event) { console.log(event); const that = this; that.setData({ isQuerying: true }) let list = db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, }); if (event > 0) { list = list.skip(event); } list.limit(5).orderBy("create_time", "desc").get().then(res => { console.log(res); const wehicles = res.data; let hasmore = true if (wehicles.length == 0) { hasmore = false } let newWehicles = []; if (event > 0) { newWehicles = that.data.wehicles.concat(wehicles); } else { newWehicles = wehicles; } newWehicles.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ wehicles: newWehicles, hasmore: hasmore, }) }); list.count().then(res => { console.log(res) that.setData({ result:res.total }) }) let list1 = db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, carpool:'我要找车' }); if (event > 0) { list1 = list1.skip(event); } list1.limit(5).orderBy("create_time", "desc").get().then(res => { const listones = res.data; let hasmore = true if (listones.length == 0) { hasmore = false } let newones = []; if (event > 0) { newones = that.data.listones.concat(listones); } else { newones = listones; } newones.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ listones: newones, hasmore: hasmore, }) }); list1.count().then(res => { console.log(res) that.setData({ result1:res.total }) }) let list2 = db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, carpool:'我要找人' }); if (event > 0) { list2 = list2.skip(event); } list2.limit(5).orderBy("create_time", "desc").get().then(res => { console.log(res); const listtwos = res.data; let hasmore = true // let hasmore = listtwos.length > 0; if (listtwos.length == 0) { hasmore = false } let newtwos = []; if (event > 0) { newtwos = that.data.listtwos.concat(listtwos); } else { newtwos = listtwos; } newtwos.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ listtwos: newtwos, hasmore: hasmore, }) }); list2.count().then(res => { console.log(res) that.setData({ result2:res.total }) }) let list3 = db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, carpool:'我找货车' }); if (event > 0) { list3 = list3.skip(event); } list3.limit(5).orderBy("create_time", "desc").get().then(res => { console.log(res); const listthrees = res.data; let hasmore = true // let hasmore = listthrees.length > 0; if (listthrees.length == 0) { hasmore = false } let newthrees = []; if (event > 0) { newthrees = that.data.listthrees.concat(listthrees); } else { newthrees = listthrees; } newthrees.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ listthrees: newthrees, hasmore: hasmore, }) }); list3.count().then(res => { console.log(res) that.setData({ result3:res.total }) }) let list4 = db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, carpool:'我要找货' }); if (event > 0) { list4 = list4.skip(event); } list4.limit(5).orderBy("create_time", "desc").get().then(res => { console.log(res); const listfours = res.data; let hasmore = true // let hasmore = listfours.length > 0; if (listfours.length == 0) { hasmore = false } let newfours = []; if (event > 0) { newfours = that.data.listfours.concat(listfours); } else { newfours = listfours; } newfours.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ listfours: newfours, hasmore: hasmore, }) }); list4.count().then(res => { console.log(res) that.setData({ result4:res.total }) }) // that.updateCount(index); that.setData({ startPoint:'', goal:'', }) }, /** * 获取选项卡计数 */ onItemChengdeEvent(event) { const that = this; var index = event.detail.index; }, /** * 获取数据库数据 */ lowdrelease(start = 0) { const that = this; let list = db.collection("wehicle"); if (start > 0) { list = list.skip(start); } list.limit(5).orderBy("create_time", "desc").get().then(res => { console.log(res); const wehicles = res.data; let hasmore = true if (wehicles.length == 0) { hasmore = false } let newWehicles = []; if (start > 0) { newWehicles = that.data.wehicles.concat(wehicles); } else { newWehicles = wehicles; } newWehicles.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ wehicles: newWehicles, hasmore: hasmore, }) }); list.count().then(res => { console.log(res) that.setData({ result:res.total }) }) let list1 = db.collection("wehicle").where({carpool:'我要找车'}); if (start > 0) { list1 = list1.skip(start); } list1.limit(5).orderBy("create_time", "desc").get().then(res => { console.log(res); const listones = res.data; let hasmore = true if (listones.length == 0) { hasmore = false } let newones = []; if (start > 0) { newones = that.data.listones.concat(listones); } else { newones = listones; } newones.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ listones: newones, hasmore: hasmore, }) }); list1.count().then(res => { console.log(res) that.setData({ result1:res.total }) }) let list2 = db.collection("wehicle").where({carpool:'我要找人'}); if (start > 0) { list2 = list2.skip(start); } list2.limit(5).orderBy("create_time", "desc").get().then(res => { console.log(res); const listtwos = res.data; let hasmore = true if (listtwos.length == 0) { hasmore = false } let newtwos = []; if (start > 0) { newtwos = that.data.listtwos.concat(listtwos); } else { newtwos = listtwos; } newtwos.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ listtwos: newtwos, hasmore: hasmore, }) }); list2.count().then(res => { console.log(res) that.setData({ result2:res.total }) }) let list3 = db.collection("wehicle").where({carpool:'我找货车'}); if (start > 0) { list3 = list3.skip(start); } list3.limit(5).orderBy("create_time", "desc").get().then(res => { console.log(res); const listthrees = res.data; let hasmore = true // let hasmore = listthrees.length > 0; if (listthrees.length == 0) { hasmore = false } let newthrees = []; if (start > 0) { newthrees = that.data.listthrees.concat(listthrees); } else { newthrees = listthrees; } newthrees.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ listthrees: newthrees, hasmore: hasmore, }) }); list3.count().then(res => { console.log(res) that.setData({ result3:res.total }) }) let list4 = db.collection("wehicle").where({carpool:'我要找货'}); if (start > 0) { list4 = list4.skip(start); } list4.limit(5).orderBy("create_time", "desc").get().then(res => { console.log(res); const listfours = res.data; let hasmore = true // let hasmore = listfours.length > 0; if (listfours.length == 0) { hasmore = false } let newfours = []; if (start > 0) { newfours = that.data.listfours.concat(listfours); } else { newfours = listfours; } newfours.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ listfours: newfours, hasmore: hasmore, }) }); list4.count().then(res => { console.log(res) that.setData({ result4:res.total }) }) }, /** * 生命周期函数--监听页面显示 */ onShow() { this.lowdrelease(0); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { this.lowdrelease(0); this.setData({ isQuerying:false }) wx.stopPullDownRefresh(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { if(!this.data.isQuerying) { this.lowdrelease(this.data.wehicles.length); }else{ this.data.isQuerying } }, })
08-03 - 查询到的计数不正确,怎么做?
如图:当在全部项查询的时候,显示正常,切换点击其他项,计数也显示正常。当我在其它项点击查询的时候,显示的计数都是全部项的计数,也就是说,全部项查询的计数是多少,在其他项点击查询的时候显示的都是全部项的计数。如果再切换各项的时候,显示的计数又正常了。请问这个问题怎么解决? [图片] components/segment/wxml代码 <view class="comment-list-group"> <view class="comment-title">全部信息(共有{{result}}条)</view> </view> components/segment/wxml代码 properties: { result :{ type:Number, value:0 }, }, index.wxml代码 <segment-carpool items="{{items}}" result="{{result}}" resultthree="{{result3}}" resultfous="{{result4}}" binditemchengde="onItemChengdeEvent" defaultIndex="0" > <view slot="0" class="segment-page wehicle-page"> <whole wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></whole> </view> <view slot="1" class="segment-page people-page"> <wehicle wx:for="{{listones}}" wx:key="key" wx:for-item="listone" list1="{{listone}}"></wehicle> </view> <view slot="2" class="segment-page train-page"> <people wx:if="{{listtwos}}" wx:for="{{listtwos}}" wx:key="key" wx:for-item="listtwo" list2="{{listtwo}}"></people> </view> <view slot="3" class="segment-page money-page"> <train wx:for="{{listthrees}}" wx:key="key" wx:for-item="listthree" list3="{{listthree}}"></train> </view> <view slot="4" class="segment-page money-page" > <money wx:for="{{listfours}}" wx:key="key" wx:for-item="listfour" list4="{{listfour}}"></money> </view> </segment-carpool> <loadingmore hasmore="{{hasmore}}" nomore="{{nomore}}"></loadingmore> index.js代码 const db = wx.cloud.database(); Page({ data: { items: ["全部", "我要找车", "我要找人", "我找货车", "我要找货"], hasmore: true, nomore: false, wehicles: [], result: 0, startPoint: [], goal: [], isQuerying: false, list:[], listones:[], listtwos:[], listthrees:[], listfours:[], }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 按条件查询数据 */ formSubmit(event) { console.log(event); const that = this; that.setData({ isQuerying: true }) let list = db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, }); if (event > 0) { list = list.skip(event); } list.limit(10).orderBy("create_time", "desc").get().then(res => { console.log(res); const wehicles = res.data; let nomore = true; let hasmore = true if (!wehicles) { nomore = false } else { hasmore = false } let newWehicles = []; if (event > 0) { newWehicles = that.data.wehicles.concat(wehicles); } else { newWehicles = wehicles; } newWehicles.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ wehicles: newWehicles, hasmore: hasmore, nomore: nomore, }) }); let list1 = db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, carpool:'我要找车' }); if (event > 0) { list1 = list1.skip(event); } list1.limit(10).orderBy("create_time", "desc").get().then(res => { console.log(res); const listones = res.data; let nomore = true; let hasmore = true if (!listones) { nomore = false } else{ hasmore = false } let newones = []; if (event > 0) { newones = that.data.listones.concat(listones); } else { newones = listones; } newones.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ listones: newones, hasmore: hasmore, nomore: nomore }) }); let list2 = db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, carpool:'我要找人' }); if (event > 0) { list2 = list2.skip(event); } list2.limit(10).orderBy("create_time", "desc").get().then(res => { console.log(res); const listtwos = res.data; let nomore = true; let hasmore = true if (!listtwos) { nomore = false } else{ hasmore = false } let newtwos = []; if (event > 0) { newtwos = that.data.listtwos.concat(listtwos); } else { newtwos = listtwos; } newtwos.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ listtwos: newtwos, hasmore: hasmore, nomore: nomore }) }); let list3 = db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, carpool:'我找货车' }); if (event > 0) { list3 = list3.skip(event); } list3.limit(10).orderBy("create_time", "desc").get().then(res => { console.log(res); const listthrees = res.data; let nomore = true; let hasmore = true if (!listthrees) { nomore = false } else{ hasmore = false } let newthrees = []; if (event > 0) { newthrees = that.data.listthrees.concat(listthrees); } else { newthrees = listthrees; } newthrees.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ listthrees: newthrees, hasmore: hasmore, nomore: nomore }) }); let list4 = db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, carpool:'我要找货' }); if (event > 0) { list4 = list4.skip(event); } list4.limit(10).orderBy("create_time", "desc").get().then(res => { console.log(res); const listfours = res.data; let nomore = true; let hasmore = true if (!listfours) { nomore = false } else{ hasmore = false } let newfours = []; if (event > 0) { newfours = that.data.listfours.concat(listfours); } else { newfours = listfours; } newfours.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ listfours: newfours, hasmore: hasmore, nomore: nomore, }) }); if(list){ list.count().then(res => { that.setData({ result: res.total, }) }); } else if(list1){ list1.count().then(res => { that.setData({ result: res.total, }) }); } else if(list2){ list2.count().then(res => { that.setData({ result: res.total, }) }); } else if(list3){ list3.count().then(res => { that.setData({ result: res.total, }) }); } else{ list4.count().then(res => { that.setData({ result: res.total, }) }); } }, /** * 初始化总计数 */ oncount(event) { const that = this; db.collection('wehicle').where({}).count().then(res => { that.setData({ result: res.total }) }); }, /** * 获取选项卡计数 */ onItemChengdeEvent(event) { console.log(event) const that = this; var index = event.detail.index; if (index == 0) { if(!that.data.isQuerying){ db.collection('wehicle').where({}).count().then(res => { that.setData({ result: res.total }) }); }else{ db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, }).count().then(res => { that.setData({ result: res.total }) }); } } else if (index == 1) { if(!that.data.isQuerying){ db.collection('wehicle').where({carpool: '我要找车',}).count().then(res => { const result = res.total; console.log(result) that.setData({ result: result, }) }); }else{ db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, carpool:'我要找车' }).count().then(res => { that.setData({ result: res.total }) }); } } else if (index == 2) { if(!that.data.isQuerying){ db.collection('wehicle').where({carpool: '我要找人',}).count().then(res => { const result = res.total; console.log(result) that.setData({ result: result, }) }); }else{ db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, carpool:'我要找人' }).count().then(res => { that.setData({ result: res.total }) }); } } else if (index == 3) { if(!that.data.isQuerying){ db.collection('wehicle').where({carpool: '我找货车',}).count().then(res => { const result = res.total; console.log(result) that.setData({ result: result, }) }); }else{ db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, carpool:'我找货车' }).count().then(res => { that.setData({ result: res.total }) }); } } else { if(!that.data.isQuerying){ db.collection('wehicle').where({carpool: '我要找货',}).count().then(res => { const result = res.total; console.log(result) that.setData({ result: result, }) }); }else{ db.collection("wehicle").where({ startPoint: that.data.startPoint, goal: that.data.goal, carpool:'我要找货车' }).count().then(res => { that.setData({ result: res.total }) }); } } }, })
07-18 - 每次刷新的时候,总是弹出Paused on breakpoint ?
如图,每次编译,或者刷新时就会弹出这个问题,请问这个是什么问题? [图片]
07-18 - 上拉加载,没有数据的情况下一直显示正在加载中,如何解决?
如图,第一次进入页面时,没有数据的情况下应该显示没有更多才对,但是现在是一直显示加载中,除非进行一次上拉动作,才会显示没有更多数据,这个问题怎么解决? [图片] components(WXML代码): <button class="loading-btn" loading="{{hasmore}}" style="height:{{height}}px;"> <block wx:if="{{hasmore}}"> <text class="loadingtext">{{loadingtext}}</text> </block> <block wx:else> <text class="loadingtext" >{{loadedtext}}</text> </block> </button> components(js代码): Component({ /** * 组件的属性列表 */ properties: { loadingtext:{ type:String, value:"正在加载中..." }, loadedtext:{ type:String, value:"没有更多数据" }, hasmore:{ type:Boolean, value:true }, height:{ type:Number, value:40 } }, }) index(wxml代码): <loadingmore hasmore="{{hasmore}}"></loadingmore> index(js代码): data: { hasmore: true, wehicles: [], }, lowdrelease(start = 0) { const that = this; let promise = db.collection("wehicle"); if (start > 0) { promise = promise.skip(start); } promise.limit(10).orderBy("create_time", "desc").get().then(res => { // console.log(res); const wehicles = res.data; let hasmore = true if(wehicles.length == 0 ){ hasmore = false } let newWehicles = []; if (start > 0) { newWehicles = that.data.wehicles.concat(wehicles); } else { newWehicles = wehicles; } // console.log(wehicles); newWehicles.forEach((wehicle, index) => { wehicle.create_time = wehicle.create_time.toString(); }) that.setData({ wehicles: newWehicles, hasmore: hasmore }) }) }, onReachBottom() { this.lowdrelease(this.data.wehicles.length); },
07-15 - 下拉刷新,真机上下拉后不回弹,上拉加载,切换页面一直显示加载中?
下拉刷新如图,模拟器正常,真机上不回弹。上拉加载,切换到其他页面时,如果没有数据或者上拉的动作,就一直显示加载中,这问题怎么解决,求助大佬 [图片][图片] wxml代码 <view class="carpool-title"> <text class="title-text">百姓同城拼车网-同城拼车</text> </view> <view class="ad-group"> <image class="ad-image" src="../../images/专注.jpg" mode="" /> </view> <view class="search-input-group"> <view class="input-group"> <input class="search-input" placeholder="出发地" /> <image class="thumbnail" src="../../images/return.png" mode="" /> <input class="search-input" placeholder="终点" /> </view> <button class="search-button" size="mini">查询</button> </view> <segment-carpool items="{{items}}" wehicle="{{wehicle}}" binditemchengde="onItemChengdeEvent" defaultIndex="0"> <view slot="0" class="segment-page wehicle-page"> <wehicle wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></wehicle> </view> <view slot="1" class="segment-page people-page"> <wehicle wx:if="{{wehicle.carpool == '我要找车'}}" wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></wehicle> </view> <view slot="2" class="segment-page train-page"> <wehicle wx:if="{{wehicle.carpool == '我要找人'}}" wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></wehicle> </view> <view slot="3" class="segment-page money-page"> <wehicle wx:if="{{wehicle.carpool == '我找货车'}}" wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></wehicle> </view> <view slot="4" class="segment-page money-page"> <wehicle wx:if="{{wehicle.carpool == '我要找货'}}" wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></wehicle> </view> </segment-carpool> <loadingmore hasmore="{{hasmore}}"></loadingmore> JS代码 const db = wx.cloud.database(); Page({ data: { items:["全部","我要找车","我要找人","我找货车","我要找货"], hasmore:true, wehicles:[], }, onLoad(options) { }, onItemChengdeEvent(event){ }, lowdrelease(start=0){ const that = this; let promise = db.collection("wehicle"); if(start>0){ promise = promise.skip(start); } promise.limit(10).orderBy("create_time", "desc").get().then(res => { const wehicles = res.data; let hasmore = true; if(wehicles.length == 0){ hasmore = false } let newWehicles = []; if(start > 0){ newWehicles = that.data.wehicles.concat(wehicles); }else{ newWehicles = wehicles; } that.setData({ wehicles:newWehicles, hasmore:hasmore }) }) }, /** * 生命周期函数--监听页面显示 */ onShow() { this.lowdrelease(); wx.stopPullDownRefresh(); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { this.lowdrelease(0); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { this.lowdrelease(this.data.wehicles.length); }, })
07-02