小程序列表切换较快,不同列表数据重复加载,这个问题怎么解决?
//快速切换头部,列表2的数据,可能会追加到列表1中,列表1的数据没来的及清空。
//头部切换
onNavBar(e) {
let navIndex = e.detail.setIndex;
this
.setData({ navIndex, showScreen:
false
, page: 1, list: [], hasMore:
null
});
this
.getOrderList();
},
//查询用工单审批列表
getOrderList() {
let reqData = {};
let lock =
this
.data.lock;
if
(lock) {
return
;
}
reqData.page =
this
.data.page;
reqData.status =
this
.data.navIndex;
if
(
this
.data.cdIds) {
reqData.cdIds =
this
.data.cdIds;
}
this
.setData({ pageState:
'frame'
, lock:
true
})
orderModel.getList(reqData).then(res => {
const tempArray =
this
.data.list.concat(res.resultData.records);
const dataState = tempArray.length > 0 ?
'finish'
:
'empty'
;
this
.setData({
lock:
false
,
list: tempArray,
pageState: dataState,
hasMore: res.hasMore
})
}).
catch
(err => {
this
.setData({ pageState:
'error'
, lock:
false
})
})
},