亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有沒有辦法為語義 UI React Dropdown 提供 html“名稱”屬性

有沒有辦法為語義 UI React Dropdown 提供 html“名稱”屬性

GCT1015 2023-09-14 18:02:05
對于普通的 html 元素,您可以通過表單獲取該元素的值。 function handleSubmit(event) {    event.preventDefault()    const formData = new FormData(e.target)    console.log(formData.get("test"))    // logs the value of the html element with the name "test"  }<form onSubmit={handleSubmit}>    <input name="test" />    <button type="submit">Submit</button></form>表單將分配一個鍵“測試”表單提交時輸入內容的值。我的問題:有沒有辦法讓此功能與語義 UI 下拉菜單一起使用?下面是我認為可行的理想情況,但我知道不行,因為該組件是其他元素的包裝器。 function handleSubmit(event) {    event.preventDefault()    const formData = new FormData(e.target)    console.log(formData.get("test"))    // logs the value of the html element with the name "test"  }<form onSubmit={handleSubmit}>    <Dropdown name="test" selection options={        [{key: '1', text: 'text', value: '1'}]      }/>    <button type="submit">Submit</button></form>提交表單時,在該下拉列表中選擇的任何值都會放入 formData 中名為“test”的鍵中。如果未選擇任何值,則為鍵“test”賦予未定義的值。這可能嗎?我還有另一個使用基本 html 選擇器的工作,但不想更改很多已經編寫的代碼。
查看完整描述

1 回答

?
收到一只叮咚

TA貢獻1821條經驗 獲得超5個贊

是的,但您需要解構下拉組件。


const [open, setOpen] = useState(false)


<Dropdown

    trigger={<Button onClick={() => setOpen(true)}>Open</Button>}

    onClose={() => setOpen(false)}

    icon={null}

    open={open}

    simple

  >

    <Dropdown.Menu>

      ... add the options with the "name" tag ...

    </Dropdown.Menu>

  </Dropdown>


查看完整回答
反對 回復 2023-09-14
  • 1 回答
  • 0 關注
  • 102 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號