Javascript 在react js中处理程序更改选择输入对象

Javascript 在react js中处理程序更改选择输入对象,javascript,reactjs,react-bootstrap,Javascript,Reactjs,React Bootstrap,我从Api映射了选项select data,但我在更改select输入值时遇到问题我使用此处理程序更改但输入不能更改值始终修复代码中的错误是什么? 如何更改输入值 我的错误是这样的,请看链接视频 同一组件中的所有代码 初始值 const initialStates = { rug: {nom: "", id: "" } } const [currentStates, setCurrentStates] = useS

我从Api映射了选项select data,但我在更改select输入值时遇到问题我使用此处理程序更改但输入不能更改值始终修复代码中的错误是什么? 如何更改输入值 我的错误是这样的,请看链接视频

同一组件中的所有代码

初始值


const initialStates = {
         rug: {nom: "", id: "" }
    }


    const [currentStates, setCurrentStates] = useState(initialStates);

处理更改方法



    const handleChange = event =>{
        setCurrentStates({ ...rugList[event.target.value].drug.id });
    };

选择输入



  <Form.Group as={Col} controlId="formGridDrug">
                                                        
<Form.Label> Select</Form.Label>
                                                       
 <Form.Control required as="select"
                                                          
  type="text"
                                                           
 id="rug.id"
                                                           
 name="rug.id"
                                                           
 value={currentStates.rug.id}
                                                           
 className={"bg-white text-dark"}
                                                           
 onChange={handleChange}
                                                      
  >
                                                         
   <option value="">Choice select</option>
                                                           
 {rugList.map((value) =>
                                                               
 <option value={value.id} key={value.id}>
                                                                  
  {value.nom}
                                                               
 </option>
                                                            
)}

                                                       
 </Form.Control>

                                                   
 </Form.Group>


挑选
选择
{rugList.map((值)=>
{value.nom}
)}

rugList
是一个数组,其中包含形状为
{id,nom}
的对象。您的
handleChange
需要在
rugList
中找到一个对象,该对象的
id
属性与
event.target.value
匹配,以正确设置
currentStates

  const handleChange = event => {
      const rug = rugList.find(({ id }) => id === event.target.value);
      if(rug) setCurrentStates({ rug });
  };

哪里是
initialStates
initialStatesinitialized-它在该组件外部吗?不,它在该组件内部错误在handel更改中无法工作我的错误类似于此问题请看此链接视频中您正在链接来自
react select
repo的问题,但您似乎没有使用此库不,我没有使用它,但是给你看视频就像是我的错误;(您使用的是react引导程序,对吗?非常感谢,它对我有用