info:api im调用具有名为vs_currency的参数。默认情况下,我需要 vs_currency 为“美元”。但是,id喜欢使用select组件在至少两个其他资产(“ btc”和“ eth”)之间进行选择。我想我希望整个表格在选择后重新加载
constructor(props) {
super(props);
this.state = {
vs_currency: 'usd',
}
}
handleOnChange = (value, event) => {
this.setState({ vs_currency: value})
console.log(this.state.vs_currency);
}
componentDidMount() {
var vs_currency = this.state.vs_currency;
axios.all([
axios.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=' + vs_currency + '&order=market_cap_desc&per_page=250&page=1&sparkline=true&price_change_percentage=1h%2C24h%2C7d%2C14d%2C30d%2C1y'),
axios.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=' + vs_currency + '&order=market_cap_desc&per_page=250&page=2&sparkline=true&price_change_percentage=1h%2C24h%2C7d%2C14d%2C30d%2C1y'),
...
}
render() {
return (
<Select key='1' defaultValue="usd" style={{ width: 80 }} onSelect={(value, event) => this.handleOnChange(value, event)}>
<Option value="usd">$ USD</Option>
<Option value="btc">Ƀ BTC</Option>
<Option value="eth">Ξ ETH</Option>
</Select>
我目前拥有的东西允许我在下拉列表中选择其他资产,但实际上并未重新加载表格并显示更新的货币:(
答案 0 :(得分:0)
首先,您需要返回从API获得的响应。
如果收到响应,您可以像这样修改您的课程:- 对于Ex:-
ORDER BY
ROW_NUMBER() OVER()
constructor(props) {
super(props);
this.state = {
Lenders: [],
selectedLender: ""
}
}
然后在<select
className="form-control"
value={this.state.selectedLender}
onChange={e =>
this.setState({ selectedLender: e.target.value })
}
>
{this.state.Lenders.map(lender => (
<option key={lender.value} value={lender.value}>
{lender.display}
</option>
))}
</select>
或getNames = () => {
fetch(
`${environment.apiURL}`
)
.then(response => {
return response.json();
})
.then(data => {
let LendersFromApi = data.map(lender => {
return { value: lender, display: lender };
});
this.setState({
Lenders: [{ value: "", display: "Select" }].concat(
LendersFromApi
)
});
})
.catch(error => {
console.log(error);
});
};
中将其命名为getNames()