I'm new to reactjs and i have a json object that i want to iterate through and populate list items in a react component. I get the json from server with an ajax call..
My ajax inside getData() method:
$.ajax(
{
type: 'get',
url: url,
success: function (data) {
this.setState({ data: JSON.parse(data) }) //or parse
}.bind(this)
},
);
Constructor:
constructor() {
super();
this.state = {
data: null
};
this.getData = this.getData.bind(this);
}
Data looks like this:
{
"commentID":25,
"matchID":43234,
"commentatorID":12537228724216704,
"timeM":67,
"timeRT":null,
"action":"goal",
"description":"aaaaaaaa"
},
{
"commentID":27,
"matchID":56,
"commentatorID":12537228724216704,
"timeM":14,
"timeRT":null,
"action":"",
"description":"fgfafafaaffaafasfasf"
},
What i've already tried is to stringify the object but when i try to iterate through the string, it's alot of work when i only want to list "description" and "timeM" .
Should i run through the json object in the render method and create list items or are there other ways to do it? I'm looking for a good example on how to do this. Thanks!