如何在本机反应中创建可搜索的下拉列表以打开特定屏幕?

时间:2019-11-08 16:57:51

标签: react-native listview routes

我正在尝试使用列表,下拉列表, enter image description here

enter image description here

如何通过此代码创建搜索列表:

 onPress={() =>this.props.navigation.navigate('LinhaDiurno03')

何时按下项目?

...。我希望列表中的每个项目在应用程序中打开一个不同的屏幕。...

我该怎么办?

这是我的睾丸:

Code to dropDown List

此处是一些代码:

 var items = [
  //name key is must.It is to show the text in front
  {id: 1, name: 'ANA RECH', prestadora: 'UNIDOS', pos: 'P01'},
  {id: 2, name: 'ARROIO DAS MARRECAS', prestadora: 'UNIDOS', pos: 'P01'},
  {id: 3, name: 'VILA SECA', prestadora: 'UNIDOS', pos: 'P01'},];

 onItemSelect={item => Alert.alert(" ", JSON.stringify(item.prestadora + ", LINHA: " + item.pos), [{ text: "open the especifc screen", onPress: () =>('some code here')},{ text: "bacvk", onPress: () => console.log("OK Pressed")}],{ cancelable: true })}
  //onItemSelect called after the selection from the dropdown

2 个答案:

答案 0 :(得分:1)

我阅读了库API,您可以在项目中设置导航键,然后在onItemSelect中进入特殊屏幕。示例代码如下。

// in the item every element add a router key
const item = [
...
{
    id: 8,
    name: 'Swift',
    key:"the navigation params" //like the example LinhaDiurno03
  },
...
]

<SearchableDropdown
            multi={true}
            selectedItems={this.state.selectedItems}
            onItemSelect={(item) => {
              his.props.navigation.navigate(item.key)
            }}
/>

答案 1 :(得分:0)

这是最终代码,您只需要在应用中进行以下操作即可... the full code