Skip to content

Instantly share code, notes, and snippets.

@bekatom
Created March 28, 2016 09:21
Show Gist options
  • Save bekatom/7e839ba0e39655a9acf1 to your computer and use it in GitHub Desktop.
Save bekatom/7e839ba0e39655a9acf1 to your computer and use it in GitHub Desktop.
react.js loop with object
var MenuCategories = React.createClass({
getInitialState: function() {
return {
data: [],
temp : "beka tomashvili"
};
},
componentDidMount: function() {
this.serverRequest = $.get(this.props.source, function (result) {
var result = result.data;
window.temp = result ;
console.log(result);
this.setState({
data: result
});
}.bind(this));
},
componentWillUnmount: function() {
this.serverRequest.abort();
},
render: function() {
return (
<ol>
{this.state.data.map(function(itm) {
return <li key={itm.id}>{itm.id}</li>;
})}
</ol>
);
}
});
ReactDOM.render(
<MenuCategories source="http://localhost:3000/v1/categories/list" />,
document.getElementById('beka')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment