更新ボタンをクリックするたびにgoogle finance APIを呼び出すと、在庫が更新されるはずです。私はこれまでのところ以下のコードを書いており、今後どのように進めるべきか分かりません。APIを呼び出してレスポンスを返す方法
ブラウザで次のエラーが表示されます。未知の型エラー:e.currentTarget.dataは関数ではありません。
おかげ
class App extends React.Component{
constructor(){
super();
this.state = {
stocks:[
{"ID":"1", "stock":"AAPL", "price": "$785.34",
"industry":"Tech"},
{"ID":"2", "stock":"WMT", "price": "$68.75",
"industry":"Tech"},
{"ID":"3", "stock":"AMZN", "price": "$810.45",
"industry":"Tech"},
{"ID":"4", "stock":"FB", "price": "$95.34",
"industry":"Tech"},
],
};
}
updateStock(e){
var stock = (e.currentTarget).data('stock');
var url=`https://www.google.com/finance/info?q=NASDAQ:${stock}`;
axios.get(url).then(response => {
var json = parser.parse(response.data);
let store = this.state.stocks;
store.price = json.l;
this.setState({
stocks: store
})
});
}
render(){
return (
<table>
<thead>
<tr>
<th> ID</th>
<th> stock</th>
<th> price</th>
<th> industry</th>
</tr>
</thead>
<tbody>
{
this.state.stocks.map((stocks) => {
return (
<tr>
<td>{stocks.ID}</td>
<td>{stocks.stock}</td>
<td>{stocks.price}</td>
<td>{stocks.industry}</td>
<td> <button onClick=
{this.updateStock}
data-stock=
{this.state.stocks.stock}>
refresh
</button>
</td>
</tr>
);
})
}
</tbody>
</table>
</div>
);
}
}
どういたしまして –
を助けたおかげで、それが助け場合、私はうれしい、私はこの答えによってupvoteと受け入れを持っている必要があります^^?それでも問題が解決しない場合は、エラーログをここに投稿してください。 – thinhvo0108