0

我必须从 URL 获取我的 JSON 并在滚动视图中显示它们,然后在到达结束时它应该再次显示它们:

start
    var REQUEST_URL = 'url';  

        export default class Json extends Component {

          constructor(props) {
            super(props);
            this.state = {
              refreshing: false,
              dataloaded: false,
              data:[],

            };
          this.onRefresh = this.onRefresh.bind(this);
          this.onEnd = this.onEnd.bind(this);

          }

         onEnd() {
          if(this.state.dataloaded)
          {
           alert("hi");



           this.setState({dataloaded:false});
          }


         }


           componentDidMount() {
            this.fetchData();
          }

          fetchData() {
            fetch(REQUEST_URL)
              .then((response) => response.json())
              .then((responseData) => {
                this.setState({
                    data:responseData,  
                  dataSource: responseData,
                  loaded: true,   
                  refreshing: false,

                });
              })
              .done();
          }

         onRefresh() {
        this.setState({
              refreshing: true,

            });


        setTimeout( () => {

        this.setState({
              refreshing: false,
              dataloaded:true,
            });

              },2000);
              this.fetchData();

          }

          render() {
              return (

                <FlatList
                    data={this.state.dataSource}
                    onRefresh = {this.onRefresh}
                    refreshing = {this.state.refreshing}
                    onEndReached  = {this.onEnd}
                    onEndReachedThreshold = {0.1}
                    renderItem={this._renderItem}
                />
               )
           }
        }
end

提前致谢。

4

0 回答 0