简体   繁体   English

如何从下拉选择器 React Native 中显示和选择项目

[英]How to show and select items from a dropdown picker React Native

I wanna create an picker dropdown inside my React Native app.我想在我的 React Native 应用程序中创建一个选择器下拉菜单。 I use React Native dropdown picker for this.我为此使用React Native 下拉选择器 With my current implementation I am only able to display something what looks like a dropdown list but I cannot open it and select the items which I added in my code.使用我当前的实现,我只能显示一些看起来像下拉列表的东西,但我无法打开它并选择我在代码中添加的项目。 What do I miss?我想念什么?

Here is my implementation:这是我的实现:

import DropDownPicker from "react-native-dropdown-picker";
import { View } from "react-native";

const Test = () => {
  return (
    <View>
      <DropDownPicker
        items={[
          { label: "Item 1", value: "item1" },
          { label: "Item 2", value: "item2", selected: true },
        ]}
        onChangeItem={(item) => console.log(item.label, item.value)}
      />
    </View>
  );
};

The documentation that you are looking at did not provide the code for a proper usage.您正在查看的文档没有提供正确使用的代码。 The actual documentation is here .实际文档在这里

import DropDownPicker from 'react-native-dropdown-picker';

function App() {
  const [open, setOpen] = useState(false);
  const [value, setValue] = useState(null);
  const [items, setItems] = useState([
    {label: 'Apple', value: 'apple'},
    {label: 'Banana', value: 'banana'}
  ]);

  return (
    <DropDownPicker
      open={open}
      value={value}
      items={items}
      setOpen={setOpen}
      setValue={setValue}
      setItems={setItems}
    />
  );
}

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

相关问题 react-native-dropdown-picker,如何从项目中获取选定的索引 - react-native-dropdown-picker, how to get selected index from Items react-native-dropdown-picker 列出的项目未正确显示(覆盖) - react-native-dropdown-picker listed items not showing properly (Overlay) react-native-dropdown-picker,如何修复下拉选择器覆盖在其他组件上 - react-native-dropdown-picker, how to fix the dropdown picker overlay on other component 如何在 react-native-dropdown-picker 中调整模型大小 - How to resize Model in react-native-dropdown-picker 如何在 react-native 中使用下拉/选择器制作 TextInput? - how to make TextInput with dropdown/picker in react-native? 如何使用 react native 中 react native 元素库中的复选框从 flatlist 中选择多个项目? - How can select multiple items from flatlist with check box from react native elements library in react native? 反应原生,select 列表中的多个项目 - React native, select multiple items from a list 如何在 react-native-select-dropdown 中从 api 动态添加数据(下拉列表)? - How to dynamically add data(dropdown list) from api in react-native-select-dropdown? 如何根据所选的选择器值显示组件? [反应原生] - how to show a component depending of picker value selected? [React native] react-native-dropdown-picker 按条件更改下拉背景颜色 - react-native-dropdown-picker changing dropdown background color by condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM