简体   繁体   中英

how to show json data by date in react native

i have json data by dates i want to show schedule time for today. how can this be implemented? json file address https://volnaveri.by/tt.json

react native code

   import React, { Component } from 'react';
import { ActivityIndicator, FlatList, Text, View } from 'react-native';

export default class App extends Component {
  constructor(props) {
    super(props);

    this.state = {
      data: [],
      isLoading: true
    };
  }

  async getMovies() {
    try {
      const response = await fetch('https://volnaveri.by/tt.json');
      const json = await response.json();
      this.setState({ data: json.times });
    } catch (error) {
      console.log(error);
    } finally {
      this.setState({ isLoading: false });
    }
  }

  componentDidMount() {
    this.getMovies();
  }

  render() {
    const { data, isLoading } = this.state;

    return (
      <View style={{ flex: 1, padding: 24 }}>
        {isLoading ? <ActivityIndicator/> : (
          <FlatList
            data={data}
            keyExtractor={({ id }, index) => id}
            renderItem={({ item }) => (
              <Text>{item.Date}, {item.Monday}, {item.Tuesday}, {item.Monday}, {item.Wednesday}, {item.Thursday}</Text>
            )}
          />
        )}
      </View>
    );
  }
};

so far this is what i got. photo

Instead of this.setState({ data: json.times });

To do:

this.setState({ data: [data.times.find(time => time.Date.split('-')[2] === new Date().getDate()))]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM