reactjs - 如何在antD select onChange中传递第二个参数?
问题描述
我想在 onchange 中访问 select 的 id。我正在尝试类似下面的东西。根据文档,第二个参数需要是对象
还有如何通过单击删除来删除这个特定的选择下拉菜单
var arr = [];
var x = NameCount
while (x > 0) {
console.log(x)
arr.push(
<div style={{width:"100%" , minWidth:'5px', marginRight:'0.5rem'}} >
<Select id={x-1} style={{ width: "100%" , minWidth:'5px'}} placeholder="Group name" onChange={(e,{key:id})=>handleGroupByname(e,{key:id})}>
{dropdown_values.map((y) => (
<Option key={y}>{y}</Option>
))}
</Select>
<span onClick={handleDelete}>delete<span>
</div>
);
x--;
}
return arr;
解决方案
对于 onchange,您可以执行以下操作:
const handleGroupByname = (value, selectId) => {
// do your stuff here
}
...
...
<Select id={x-1} onChange={(value)=>handleGroupByname(value, x-1)}>
...
...
</Select>
对于删除,您可以应用相同的想法
const handleDelete = (e, id) => {
// find the id and
// remove the item from you arr
}
<span onClick={(e) => handleDelete(e, x-1)}>delete<span>
推荐阅读
- asp.net - 从 Web 访问配置文件 - 无 AppSettings
- python - 在密文转换中添加空格
- c# - 与 GUI 更新并行运行两个任务
- android - 将 If 语句添加到列表视图还是有其他方法?
- php - PayPal _xclick-subscriptions 不适用于沙盒
- react-native - 在 FlatList 的当前顶行上方插入新项目,而不会造成自动 scrollToTop
- python-3.x - 如何使用 dask.distributed 并行化嵌套循环?
- xslt - XSL 以及如何删除重复项
- ios - 将 localforage-cordovasqlitedriver 安装到我的项目中时缺少 localforage.js 文件
- java - 如何解决这个 Tesseract !strcmp(locale, "C") 错误?