How to implement the React-native-Calendars component

0

I would like to know how to fill the react-native-calendar component, take example example / src / screens / agenda.js click here

When trying to fill my agenda with the Json of my web service, which is in this way

datos: [
    {
        estado: "PENDIENTE",
        cod: "1",
        desc: "Cita 1",
        fechaini: "2018-03-16 10:30:48",
        fechafin: "2018-03-16 12:01:37",
        lugar: "GIRON",
    },
    {
        estado: "PENDIENTE",
        cod: "2",
        desc: "cita 2",
        fechaini: "2018-04-16 10:30:48",
        fechafin: "2018-04-16 12:01:37",
        lugar: "GIRON",
    },
    {
        estado: "PENDIENTE",
        cod: "3",
        desc: "Cita 3",
        fechaini: "2018-04-16 12:30:48",
        fechafin: "2018-04-16 14:01:37",
        lugar: "GIRON",
    },
    {
        estado: "PENDIENTE",
        cod: "4",
        desc: "PPPPPPP",
        fechaini: "2018-04-25 10:30:48",
        fechafin: "2018-04-25 12:01:37",
        lugar: "GIRON",
    },
]

And so I receive it in react

getEventos = () => {

  fetch(url)
  .then(res=>res.json())
  .then(res => {
    this.setState({
      data:res.datos
    })
  })      
}

and here I implement it in the add-on

loadItems(day) {
setTimeout(() => {
  this.getEventos()

  this.state.data.map((item) => {
    const fecha = item.fechaini.split(" ")[0].trim()
    if (!this.state.items[fecha]) {
      this.state.items[fecha] = [];
      const numItems =1;
      for (let j = 0; j < numItems; j++) {
        this.state.items[fecha].push({
          name:  item.desc,
        })
      }
    }
  })  

  // this.getLogin()
  console.warn(this.state.items);
  const newItems = {};
  Object.keys(this.state.items).forEach(key => {newItems[key] = this.state.items[key];});
  this.setState({
    items: newItems
  })
}, 1000)

}

The problem lies in the following when I take my view only the first json event takes me, that is, if in one day there is more than one appointment, it only takes me the first appointment that is found in the JSon.

Apart I need to do so that if there are no appointments on that day the array "items" I use in react when there are no appointments in the day is believed but emptied.

    
asked by joaquin carreño 31.05.2018 в 16:33
source

0 answers