【问题标题】:How to pass the second argument in antD select onChange?如何在antD select onChange中传递第二个参数?
【发布时间】:2021-09-25 02:03:37
【问题描述】:
  1. 我想在 onchange 中访问 select 的 id。我正在尝试一些东西 如下所示。第二个参数需要根据 文档

  2. 还有如何通过点击删除这个特定的选择下拉菜单 删除

 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;

【问题讨论】:

    标签: reactjs antd


    【解决方案1】:

    对于 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
    }
    

    &lt;span onClick={(e) =&gt; handleDelete(e, x-1)}&gt;delete&lt;span&gt;

    【讨论】:

      猜你喜欢
      • 2020-12-23
      • 2011-06-28
      • 1970-01-01
      • 2014-06-23
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      • 2022-08-22
      • 1970-01-01
      相关资源
      最近更新 更多