如图,当点击查询后清空输入框的值,但是上拉加载更多时失效,获取不到数据,这个要怎么做?
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);
}
},
提供一个能复现的代码片段吧