I'm new to React and I'm a little crazy trying to figure out what I'm doing wrong. I am trying to iterate through a json array that I get from an ajax call. When I mock the data, it works fine, but when I make an ajax call to get the exact data, it gives me undefined is not a function (evaluating 'this.state.list.map()')
array:
[ { "name": "drop1" }, { "name": "drop2" }, { "name": "drop3" } ]
function:
var List = React.createClass({ getInitialState: function() { return {data: {}}; }, componentDidMount: function() { $.ajax({ url: ACTUAL_URL, dataType: 'json', success: function(data){ this.setState({data: data}); }.bind(this), error: function(xhr, status, err){ console.error(url, status, err.toString()); }.bind(this) }); }, render: function() { return ( <ul className="droplist"> {this.state.data.map(function(l){ return (<li>{l.name}</li>) })} </ul> ); } });
Any help is greatly appreciated.
javascript ajax reactjs react-jsx
this_is_ender
source share