【发布时间】:2018-12-18 03:38:41
【问题描述】:
如何使用 React Native 的 FlatList 增加负载 (不是无限的)
我已经这样做了,但不幸的是它会无限加载。
这是我的代码 sn-p
<FlatList
data={this.props.data}
renderItem={({ item, separators }) => (
<TouchableHighlight
onPress={() => this._onPress(item)}
onShowUnderlay={separators.highlight}
onHideUnderlay={separators.unhighlight}
>
<Text> {item.title} </Text>
</TouchableHighlight>
)}
keyExtractor={item => item.id}
ListFooterComponent={this.renderFooter}
onEndReached={this.props.handleLoadMore}
onEndThreshold={0}
/>
还有我的handleLoadMore
handleLoadMore = () => {
console.log("test"); // <---- this line run infinitely
fetch(url, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify(filters)
})
.then(response => response.json())
.then(responseJson => {
this.setState({
itemData: [
...this.state.itemData,
...responseJson.estate_list
],
itemPage: this.state.itemPage + 1
});
})
.catch(error => {
console.error(error);
});
};
【问题讨论】:
-
如何在 this.props.handleLoadMore() 函数中加载数据?
-
@nikolay-tomitov 更新了我的问题
-
@Mahdi Bashirpour,您使用了错误的 FlatList 道具。没有这样一个名为“onEndThreshold”的道具。它应该是“onEndReachedThreshold”。
-
@sandip-lipane 这两个我都用过,但问题没有解决
标签: javascript react-native react-native-flatlist