for loop in react

前端 未结 1 1394
不知归路
不知归路 2021-01-11 23:38

I got this function working to get some gym classes from a .json file.

    filtrarClase(dia, hora) {
    let data = this.state.data
    return data.filter(cl         


        
1条回答
  •  执笔经年
    2021-01-12 00:18

    Reason is, for loop is used to iterate the array it will never return anything, if you want to return something then use map.

    Write it like this:

    actualizarLista(dia){
        const horas = ['07:30','08:15','08:30','09:30','10:30','15:00','15:15','15:30','17:30','18:00','18:15','18:30','19:00','19:30','20:00','20:30','21:30']
        return horas.map((el, i) => {
            return 
      {this.filtrarClase(dia, el)}
    }) } render() { let dias = [1,2,3,4,5,6]; let uiItems = dias.map(i => { return
    {this.actualizarLista(i)}
    }) return (
    {uiItems}
    ) }

    Suggestion: horas array is constant so i will suggest you to define it once outside of the class.

    0 讨论(0)
提交回复
热议问题