【发布时间】:2017-05-22 13:42:54
【问题描述】:
到目前为止,这是我的代码,它根据“基本”汇率和选定日期提取历史货币数据。有没有办法显示“货币名称”和“汇率”列中返回的数据?到目前为止,我的代码如下:http://codepen.io/co851002/pen/PWqVwr
var date = '2017-01-06'
var base = 'USD'
var API_request = 'https://api.fixer.io/' + date + '?base=' + base;
var App = React.createClass({
getInitialState: function() {
return {
rates: []
}
},
componentDidMount: function() {
var th = this;
this.serverRequest =
axios.get(API_request)
.then(function(result) {
console.log(result.data.rates)
th.setState({
rates: result.data.rates
});
})
},
componentWillUnmount: function() {
this.serverRequest.abort();
},
render: function() {
var self = this;
return (
<div className="table">
<table >
<thead>
<tr>
<th>Currency</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Currency goes here</td>
<td>Value goes here</td>
</tr>
</tbody>
</table>
</div>
)
}
});
React.render(<App />, document.querySelector("#root"));
【问题讨论】:
标签: javascript object reactjs dictionary