[英]pass id and value to set of select input in react js
i have this set of select input that shows numbers on intail load on select filed and then i want to change value based on the option also i want to pass a id to the post api called user.id我有这组 select 输入,显示在 select 归档的最终负载上的数字,然后我想根据该选项更改值,我还想将一个 ID 传递给名为 user 的帖子 Z8A5DA52ED126447D359E70C0572
{
data.map((user) => (
<select
value={user.numberfromapi} // to show the number that is fecteched from api in intial load
style={{ background: defaultcolor }}
onChange={handleBackground(user.id ,value)} // i want to pass these 2 filds
>
<option value="1"> 1 </option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
));
}
You can modify handleBackground
to look like this.您可以将
handleBackground
修改为如下所示。
const handleBackground = (userId) => ({ target }) => {
let value = target.value;
// you can use userId and value here.
}
Then in your JSX call handleBackground
like this.然后在你的 JSX 中调用
handleBackground
像这样。
<select
value={user.numberfromapi}
style={{ background: defaultcolor }}
onChange={handleBackground(user.id)}
>
Or do it the sloppy way like this.或者像这样草率地做。
<select
value={user.numberfromapi}
style={{ background: defaultcolor }}
onChange={(event) => handleBackground(user.id, event.target.value)}
>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.