0
Follow an example of the object in question :
obj : {
"bairro" : "Centro",
"dAula" : {
"Quarta" : true,
"Segunda" : true
},
"dVencimento" : "10",
"dataCadastro" : "10/10/2017",
"dataInicioContrato" : "27/11/2018",
"mensalidades" : {
"2018" : {
"fev" : true,
"jan" : true,
"mar" : true
}
},
"numero" : "111 apto 201",
}
I receive a list of students by this.props.list and include them in a table as follows:
class TabelaMensalidade extends Component {
render() {
return(
<tbody>
{
this.props.lista.map((aluno)=>{
return (
<tr key={aluno.key}>
<td>{aluno.bairro}</td>
<td>{aluno.dVencimento}</td>
<td>{aluno.dataCadastro}</td>
<td>{aluno.dataInicioContrato}</td>
<td>{aluno.dAula.Quarta}</td>
<td mes='jan' data-value={aluno.mensalidades.2018.jan}>{aluno.mensalidades.2018.jan}
</tr>
)
})
}
</tbody>
)
}
}
However I cannot access the data in aluno.mensalidades.2018.jan
, whereas in dAula.Quarta
I get it, follow the mistake:
Uncaught TypeError: Cannot read property 'jan' of undefined
I’ve tried to use aluno.mensalidades[2018].jan
and aluno.mensalidades['2018'].jan
and the error remains the same
I think my problem lies in the way I’m pulling the object from the bank. I’ll edit the question
– Matheus Hatje
I believe that no matter how you do it, using the dot syntax will not work. You need to select using
[]
when the property name is a number or starts with any value other than _ $ or a letter. Doobj.mensalidades[2018].jan
works perfectly, what your difficulty?– Máttheus Spoo
Using
aluno.mensalidades[2018].jan
, inside the map returns the error,Uncaught TypeError: Cannot read property 'jan' of undefined
, I have tried putting quotes too, as for examplealuno.mensalidades['2018'].jan
– Matheus Hatje
Sorry, the answer is correct, what happened was that some students did not have this value in the bank ( because they did not pay) I ended up not filtering them and the error was generated by not entering the value inside the object
– Matheus Hatje