简体   繁体   English

我怎样才能让这个下拉列表显示所有五十个州而不是“选项#”

[英]How can I make this dropdown show all of the fifty states instead of “option #”

Right now this code shows a dropdown form that lists "option #".现在,这段代码显示了一个列出“选项#”的下拉表单。 How can I make all of the fifty states selectable instead of the option and a number?如何使所有 50 个州都可选择而不是选项和数字?

import React, { useState } from 'react';
    
    import { 
        Box, 
        FormField, 
        Grommet, 
        Select, 
        MaskedInput,
        TextInput 
    } from 'grommet';
    import { grommet } from 'grommet/themes';
    
    const allOptions = Array(50)
      .fill()
      .map((_, i) => `option ${i + 1}`);
    
    export const Simple = () => {
      const [value, setValue] = useState('');
    
      return (
        <Grommet theme={grommet}>
          <Box align="center"  background="light-2" >
            <FormField label="State" htmlFor="select" >
              <Select
                id="select"
                placeholder="placeholder"
                options={allOptions}
                value={value}
                onChange={({ option }) => setValue(option)}
              />
            </FormField>
    </Box>
                </Grommet>
      );
    };
    export default {
      title: 'Input/FormField/Simple',
    };

Please be mindful to use Form+FormField wrappers if required by your app.如果您的应用需要,请注意使用 Form+FormField 包装器。 If the Form context isn't required please remove the FormField wrapper.如果不需要 Form 上下文,请删除 FormField 包装器。

import React, { useState } from "react";
import { render } from "react-dom";

import { Box, FormField, Grommet, Select } from "grommet";
import { grommet } from "grommet/themes";

// https://gist.github.com/tleen/6299431
const allOptions = [
  "Alabama",
  "Alaska",
  "American Samoa",
  "Arizona",
  "Arkansas",
  "California",
  "Colorado",
  "Connecticut",
  "Delaware",
  "District of Columbia",
  "Federated States of Micronesia",
  "Florida",
  "Georgia",
  "Guam",
  "Hawaii",
  "Idaho",
  "Illinois",
  "Indiana",
  "Iowa",
  "Kansas",
  "Kentucky",
  "Louisiana",
  "Maine",
  "Marshall Islands",
  "Maryland",
  "Massachusetts",
  "Michigan",
  "Minnesota",
  "Mississippi",
  "Missouri",
  "Montana",
  "Nebraska",
  "Nevada",
  "New Hampshire",
  "New Jersey",
  "New Mexico",
  "New York",
  "North Carolina",
  "North Dakota",
  "Northern Mariana Islands",
  "Ohio",
  "Oklahoma",
  "Oregon",
  "Palau",
  "Pennsylvania",
  "Puerto Rico",
  "Rhode Island",
  "South Carolina",
  "South Dakota",
  "Tennessee",
  "Texas",
  "Utah",
  "Vermont",
  "Virgin Island",
  "Virginia",
  "Washington",
  "West Virginia",
  "Wisconsin",
  "Wyoming"
];

export const App = () => {
  const [value, setValue] = useState("");

  return (
    <Grommet theme={grommet}>
      <Box align="center" background="light-2">
        <FormField label="State" htmlFor="select">
          <Select
            id="select"
            placeholder="placeholder"
            options={allOptions}
            value={value}
            onChange={({ option }) => setValue(option)}
          />
        </FormField>
      </Box>
    </Grommet>
  );
};

render(<App />, document.getElementById("root"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据下拉列表中的选定选项显示元素 - How can I show an element depending on selected option in a dropdown 如何显示特定于所选下拉选项的项目? - How can I show items specific to a selected dropdown option? 如何在使用JavaScript或Ajax的下拉列表中显示每个选项的工具提示? - How can I show a tooltip for each option on a dropdown with JavaScript or Ajax? 如何使此下拉列表始终显示在父div之外? - How can I make this dropdown always show beyond the parent div? jQuery:如何从“全部显示”选项中隐藏类别? - jQuery: How can I hide a category from the Show All option? 我该如何使用<ul>列表而不是<select>用于向每个选项添加图像的下拉菜单? - How can I use <ul> list instead of <select> dropdown for adding images to every option? 我怎样才能使它显示菜单上的所有内容而不必搜索? - How can I make this to show everything on the menu instead of having to search? 如何使底部的console.log等到全部完成,然后显示答案而不是等待? - How can I make the console.log at the bottom wait until its all complete, then show me the answer instead of waiting? 如何突出显示下拉菜单中的选项? - How can I highlight an option in a dropdown menu? 如何根据下拉列表中当前选择的选项显示特定数据? - how can i show specific data based on currently selected option in a dropdown list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM