Skip to content

Instantly share code, notes, and snippets.

@rippo
Created March 24, 2015 17:48
Show Gist options
  • Save rippo/d45ecbed2ad659a1c75c to your computer and use it in GitHub Desktop.
Save rippo/d45ecbed2ad659a1c75c to your computer and use it in GitHub Desktop.
React show list from a AJAX call
var MachineInfo = React.createClass({
getInitialState: function() {
return {
data: []
};
},
componentDidMount: function() {
$.get(this.props.source, function(result) {
this.setState({
data: result
});
}.bind(this));
},
render: function() {
var createItem = function(item) {
return <p>{item.Id} {item.Key} {item.Value} </p>;
};
return <div>{this.state.data.map(createItem)}</div>;
}
});
React.render(
<MachineInfo source="/ajax/namevalues/2" />,
document.getElementById('reactdiv')
);
[
{"Id":5,"Key":"Temp","Value":"160"},
{"Id":6,"Key":"Pressure","Value":"Light"},
{"Id":7,"Key":"Time","Value":"Pre 10 Press 20"},
{"Id":8,"Key":"Release","Value":"Warm"}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment