How to make a searchable droplist in react native to open an specific screen?

痞子三分冷 提交于 2020-01-25 06:52:10

问题


I'm trying to make a search bar with a list,dropdown list,

how to make a search list lik this code:

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

when an item is pressed?

....I want that each item in the list open a different screen in the application....

How can i to it?

here is the my teste:

Code to dropDown List

here some code:

 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

回答1:


I read the library API, you can set the navigation keys in the item, then in the onItemSelect to go to the special screen. the example code is below.

// 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)
            }}
/>



回答2:


Here is the final code, you just need to make the route before in your app... the full code



来源:https://stackoverflow.com/questions/58770848/how-to-make-a-searchable-droplist-in-react-native-to-open-an-specific-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!