当用户滚动到结束时,如何对我的滚动视图进行分页?
How can I paginate my scrollview when the user scrolling until end?
我想在我的滚动视图中显示交易列表,但是当用户滚动它直到结束时,另一个请求将启动并在我的视图中添加其他页面的交易。我该怎么做
这是我的第一个请求,它获取交易的第一页
let { data } = await client.get('/coins/2/transactions');
let transactions = {};
transactions = data.map(e => {
return {
address: e.address,
amount: e.amount,
blockhash: e.blockhash,
confirmations: e.confirmations,
status: e.status,
timestamp: e.timestamp,
txid: e.txid
};
})
this.setState({ transactions });
}
然后我添加了另一个功能,就是获取下一页。
async getNextCursor(cursor){
let {data} = await client.get('/coins/2/transaction/?cursor=' + cursor)
let transactions = {};
transactions = data.map(e => {
return {
address: e.address,
amount: e.amount,
blockhash: e.blockhash,
confirmations: e.confirmations,
status: e.status,
timestamp: e.timestamp,
txid: e.txid
};
})
return transactions
}
如何在滚动结束时运行此请求并获取其他事务并添加到我的事务状态中也显示它?
注意:我的请求给我 has_more(bool) 和 next_cursor(int) 属性
这是一个粗略的代码示例
<ScrollView
scrollEventThrottle={16}
onScroll={handlePagination}
/>
使用函数切换特定点的数据,
handlePagination=(event)=>{
const currentY = event.nativeEvent.contentOffset.y
if(currentY==BOTTOM){
const data = this.getNextCursor();
this.setState({ data });
}
}
BOTTOM是切换数据时的高度变量
我想在我的滚动视图中显示交易列表,但是当用户滚动它直到结束时,另一个请求将启动并在我的视图中添加其他页面的交易。我该怎么做
这是我的第一个请求,它获取交易的第一页
let { data } = await client.get('/coins/2/transactions');
let transactions = {};
transactions = data.map(e => {
return {
address: e.address,
amount: e.amount,
blockhash: e.blockhash,
confirmations: e.confirmations,
status: e.status,
timestamp: e.timestamp,
txid: e.txid
};
})
this.setState({ transactions });
}
然后我添加了另一个功能,就是获取下一页。
async getNextCursor(cursor){
let {data} = await client.get('/coins/2/transaction/?cursor=' + cursor)
let transactions = {};
transactions = data.map(e => {
return {
address: e.address,
amount: e.amount,
blockhash: e.blockhash,
confirmations: e.confirmations,
status: e.status,
timestamp: e.timestamp,
txid: e.txid
};
})
return transactions
}
如何在滚动结束时运行此请求并获取其他事务并添加到我的事务状态中也显示它?
注意:我的请求给我 has_more(bool) 和 next_cursor(int) 属性
这是一个粗略的代码示例
<ScrollView
scrollEventThrottle={16}
onScroll={handlePagination}
/>
使用函数切换特定点的数据,
handlePagination=(event)=>{
const currentY = event.nativeEvent.contentOffset.y
if(currentY==BOTTOM){
const data = this.getNextCursor();
this.setState({ data });
}
}
BOTTOM是切换数据时的高度变量