如图:当查询的时候,下拉刷新或上拉加载时,加载的是查询后的数据,而不是加载全部项的数据。现在的bug就是,当查询后的数据没有了,加载的就是全部项的数据。这个问题怎么解决?
代码:
data: {
hasmore: true,
wehicles: [],
startPoint:'',
goal:'',
},
/**
* 按条件查询数据
*/
formSubmit(start){
const that = this;
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_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,
})
})
},
/**
* 获取数据库数据
*/
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 || !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
})
})
},
onReachBottom() {
this.lowdrelease(this.data.wehicles.length);
this.formSubmit(this.data.wehicles.length)
},