【发布时间】:2018-05-05 19:00:21
【问题描述】:
我的技能是基本的,我是 React Native 的新手,我想做的是将帖子限制在 12 以内,当用户滚动时自动加载更多帖子。
我的代码:
export default class Posts extends Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,};}
componentDidMount() {
return fetch(ConfigApp.URL+'json/data_posts.php')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataPosts: responseJson
}, function() {
});
})
.catch((error) => {
});}
render() {
return (
<FlatList
data={ this.state.dataPosts }
numColumns={2}
renderItem={({item}) =>
<TouchableOpacity activeOpacity={1} style={{flex: 1}}>
<View style={{margin: 5, marginLeft: 4}}>
<ImageBackground source={{uri: ConfigApp.IMAGESFOLDER+item.post_image}}>
<LinearGradient colors={['rgba(0,0,0,0.3)', 'rgba(0,0,0,0.8)']}>
<Text numberOfLines={2}>{item.post_title}</Text>
</LinearGradient>
</ImageBackground>
</View>
</TouchableOpacity>
}
keyExtractor={(item, index) => index}
/>
);}}
【问题讨论】:
-
您是想从服务器加载更多数据,还是一次性加载所有数据,最初只显示其中的 12 个?
-
是的,第二个选项
-
你最初得到多少数据长度,调用下一组项目的api有什么限制吗?
-
我找到了这个库,但我不知道如何使用它github.com/BBuzzArt/react-native-infinite
标签: reactjs react-native