问题:如图,通过条件查询后得到是数据,列表中可以正常显示,当查询的数据没有之后,会继续加载全部项的数据,并且查询得到的数据会重新加载一次。
想要的效果:当查询得到的数据加载完之后,应该不再加载数据。显示没有更多数据。如果没有查询操作,正常显示并加载全部项的数据。更多代码可查看代码片段。求大师指点
全部代码可打开代码片段:
https://developers.weixin.qq.com/s/AgQ0nEmj7SSR
WXML代码:
<view class="carpool-title">
<text class="title-text">百姓同城拼车网-同城拼车</text>
</view>
<view class="ad-group">
<image class="ad-image" src="../../images/专注.jpg" mode="" />
</view>
<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>
<segment-carpool items="{{items}}" countwe="{{result}}" 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 wx:if="{{wehicles.startPoint && wehicles.goal}}" hasmore="{{hasmore}}"></loadingmore>
<loadingmore else hasmore="{{hasmore}}"></loadingmore>
const db = wx.cloud.database();
const _ = db.command
Page({
/**
* 页面的初始数据
*/
data: {
items: ["全部", "我要找车", "我要找人", "我找货车", "我要找货"],
hasmore: true,
wehicles: [],
result: 0,
startPoint:'',
goal:'',
isQuerying:false
},
/**
* 按条件查询数据
*/
formSubmit(start){
const that = this;
that.setData({
isQuerying:true
})
let promise = db.collection("wehicle").where({
startPoint:that.data.startPoint,
goal:that.data.goal,
});
if(start > 0){
promise = promise.skip(start);
}
promise.limit(10).orderBy("create_itme","desc").get().then(res => {
const wehicles = res.data;
let hasmore = true;
if(wehicles.length == 0 || !wehicles){
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,
isQuerying:false
})
})
},
/**
* 获取数据库数据
*/
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
})
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
this.lowdrelease();
// this.formSubmit()
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
this.lowdrelease(0);
wx.stopPullDownRefresh();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
// this.formSubmit(this.data.wehicles.length)
if(this.data.isQuerying){
this.formSubmit(this.data.wehicles.length)
}else{
this.lowdrelease(this.data.wehicles.length);
}
},
})