简体   繁体   English

如何在 React Native 中按日期显示 json 数据

[英]how to show json data by date in react native

i have json data by dates i want to show schedule time for today.我有 json 日期数据,我想显示今天的日程安排时间。 how can this be implemented?如何实施? json file address https://volnaveri.by/tt.json json 文件地址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 });而不是 this.setState({ data: json.times });

To do:去做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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