當它們嵌套在數組中時,我無法選擇/捕獲單個選擇選項?,F在,當在任何數組元素中單擊一個選擇選項時,所有選項都會更改為該值?,F在我的設置非常標準,可以與單個下拉選擇輸入一起使用。我不知道如何繼續解決這個問題。這是我的設置:const array = [ { thing: "itemone", thingArr: [1, 2, 3, 4] }, { thing: "itemtwo", thingArr: [1, 2, 3, 4] }, { thing: "itemthree", thingArr: [1, 2, 3, 4] }, { thing: "itemfour", thingArr: [1, 2, 3, 4] }];function App() { const [quantity, setQuantity] = useState(1); const onSelectChange = e => { setQuantity(e.target.value); }; return ( <div className="App"> {array.map(item => ( <div key={item.thing}> <p>{item.thing}</p> <select value={quantity} onChange={onSelectChange}> {item.thingArr.map(option => ( <option key={option} value={option}> {option} </option> ))} </select> </div> ))} </div> );}同樣,我只希望單擊的選擇選項進行更改;現在,當單擊任何給定的選擇選項時,它們都會發生變化。
當數據嵌套在數組中時捕獲單個選擇下拉值
海綿寶寶撒
2021-06-15 10:48:44