我想在我的反应原生应用程序中分页,所以下面是我的代码
<ListView bounces={false}
enableEmptySections={ true }
automaticallyAdjustContentInsets={ false }
dataSource={this.state.dataSourceRadio}
renderRow={(rowData, sectionID, rowID) => this.renderSiteView(rowData, rowID)}
onEndReached={this.onEndReached}
/>
onEndReached() {
if (!this.state.waiting) {
this.state.offset=10,
this.APIGetSiteGPS(this.state.token);
}
}
当我在上面运行代码时,下一页数据不会出现,所以我怎么能解决这个问题?你的所有建议都很明显
我在此方法中更新了我的观点
_bindingRadioButtonData(data) {
this.setState({
dataSourceRadio: this.state.dataSourceRadio.cloneWithRows(data),
})
}
API调用方法
APIGetSiteGPS(token) {
console.log(TAG + "customer Api: " + APPCONSTANTS.BASE_URL + "site" + " " + token)
fetch(APPCONSTANTS.BASE_URL + "site?&offset=" + this.state.offset, {
method: APPCONSTANTS.API_METHOD.GET,
headers: {
'Accept': APPCONSTANTS.HEADERS.VALUE.ACCEPT,
'Content-Type': APPCONSTANTS.HEADERS.VALUE.CONTENT_TYPE,
'Authorization': 'Bearer ' + token,
},
})
.then(response => {
const statusCode = response.status;
const data = response.json();
// data: offset === 0 ? res.results : [...this.state.siteList, ...res.results];
return Promise.all([statusCode, data]);
})
.then((res, data) => {
this.responseReceive(res)
})
.catch((error) => {
this.stopLoadingIndicator()
console.log('error..', error);
})
}
responseReceive(response) {
this.stopLoadingIndicator()
console.log(TAG + 'Response-->' + JSON.stringify(response));
var temp = this.state.siteList;
if (response[0] == APPCONSTANTS.API_RESPONSE_STATUS.SUCCESS) {
for (let i = 0; i < response[1].data.sites.length; i++) {
temp.push(response[1].data.sites[i]);
}
this.setState({ siteList: temp})
setTimeout(() => {this._bindingRadioButtonData(this.state.siteList)}, 1000)
this.setState({isFirstDataLoad:true});
//this.onEndReached();
} else {
Alert.alert(APPCONSTANTS.APP_NAME, response[1].message)
}
}