Created
March 24, 2015 17:48
-
-
Save rippo/d45ecbed2ad659a1c75c to your computer and use it in GitHub Desktop.
React show list from a AJAX call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{"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