gpt4 book ai didi

javascript - 在 react 中使用事件

转载 作者:行者123 更新时间:2023-11-30 14:27:08 25 4
gpt4 key购买 nike

所以我想做的是当有人点击一个选项时我想在 onChange 调用期间发送两个参数。我怎样才能设法发送事件和第二个参数?我可以想出一种不需要我发送第二个参数来解决这个问题的方法,但我想知道我是否可以发送事件和另一个参数。

      {this.state.watchedMovies.map((movie, index) => (
<div className="txn-row" key={index}>
<div className="txn-data">{movie.moviename}</div>

<div className="txn-data">
<select className="scorebar" onChange={() => this.changescore(event, movie)}>
<option>{movie.score > 10 ? <span>Rate</span> : movie.score}</option>
{this.state.grades.map((grade, index) =>(
<option value={grade} key={index}>{grade}</option>
))}
</select>
</div>

</div>
))}

最佳答案

赋予 onChange 的函数将以事件作为第一个参数调用,因此您需要将其传递给您的 changescore 方法。

<select
className="scorebar"
onChange={(event) => this.changescore(event, movie)}
>

关于javascript - 在 react 中使用事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51757119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com