簡體   English   中英

如何在 React 中獲取 office-ui-fabric-react/lib/Dropdown 鍵的值

[英]How to get value of key of office-ui-fabric-react/lib/Dropdown in React

我使用 office-ui-fabric-react/lib/Dropdown 在我的反應應用程序中創建了下拉列表

const fundsTypes: IDropdownOption[] =
    [
        { key: "Electronic", text: "Electronic" },
        { key: "BankCheque", text: "Bank Cheque" },
        { key: "TrustCheque", text: "Trust Cheque" },
        { key: "PersonalCheque", text: "Personal Cheque" }
    ];

<div className="ms-Grid-col ms-sm4">
  <Dropdown
     placeholder='Select Funds Type'
     data-cy='funds_type_input'
     options={fundsTypes}
     defaultSelectedKey={updatedState['fundType']}
     onChange={(ev, newItem) => this.props.updateValue(newItem!.key, 'fundType')}/>
  </div>

我將密鑰存儲在數據庫中,現在我想根據頁面上某處的密鑰獲取價值,但我無法做到。 我在互聯網上搜索了很多,但沒有得到解決方案。

現在我最終想要的是,獲得一個鍵的值。 例如,如果我通過鍵“ PersonalCheque ”,那么值應該是Personal Check 我嘗試了 fundTypes["PersonalCheque"] 但沒有用。

任何人都可以幫忙嗎?

在文檔https://developer.microsoft.com/en-us/fluentui#/controls/web/dropdown我看到selectedKeys道具

添加時,您必須將所選鍵存儲在狀態或某處。

 <Dropdown
     placeholder='Select Funds Type'
     data-cy='funds_type_input'
     options={fundsTypes}
     defaultSelectedKey={updatedState['fundType']}
     onChange={(ev, newItem) => this.props.updateValue(newItem!.key, 'fundType')}
     selectedKeys={["PersonalCheque"]} // here will be value from your state
/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM