/
app.jsx
71 lines (66 loc) · 1.79 KB
/
app.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var WeatherImage = React.createClass({
render: function() {
return (
<img src="sunny.png" />
);
}
});
var WeatherTemperature = React.createClass({
render: function() {
var that = this;
return (
<h3>{this.props.temperature}</h3>
);
}
});
var WeatherCity = React.createClass({
render: function() {
return (
<h3>{this.props.zip}</h3>
);
}
});
var WeatherApp = React.createClass({
getInitialState: function() {
return {
zip: '32703',
temperature: '100'
}
},
componentWillMount: function() {
var that = this;
$.get('http://api.openweathermap.org/data/2.5/weather?zip=' + this.state.zip).success(function(data) {
that.setState({
temperature: data['main']['temp']
});
});
},
render: function() {
return (
<div className="container">
{/* city */}
<div className="row">
<div className="col-xs-3 col-xs-offset-4">
<WeatherCity zip={this.props.zip} />
</div>
</div>
{/* temperature */}
<div className="row">
<div className="col-xs-6 col-xs-offset-3">
<WeatherTemperature />
</div>
</div>
{/* image */}
<div className="row">
<div className="col-xs-6 col-xs-offset-3">
<WeatherImage />
</div>
</div>
</div>
);
}
});
React.render(
<WeatherApp zip="32703" />,
document.getElementById('content')
);