sohobloo / react-native-modal-dropdown

A react-native dropdown/picker/selector component for both Android & iOS.
MIT License
1.19k stars 477 forks source link

How to get the selected item from the dropdown in the "onSelect" function? #143

Closed sojimon closed 6 years ago

sojimon commented 6 years ago

I am new to react native.I used the react-native-modal-dropdown for a dropdown.I need to get the selected option in the "onSelect " function.I tried.And the code is given below.

<ModalDropdown defaultValue='(Select)' options={['react', 'react-native']} style={{borderWidth:1,borderColor:'grey',width:'100%',height:30,borderRadius:5,marginTop:5,height:25,paddingLeft:5}} dropdownStyle={{width:'95%'}} onSelect={(e)=>{this.onTagSelect(e)}}>

And my function is onTagSelect(e){ console.log("======== on tag selected ===========") console.log(e) }

And the '0' and '1' get consoled .

sohobloo commented 6 years ago

onSelect takes tow args as index and rowData.

your code should like this:

onSelect={(idx, data)=>{this.onTagSelect(idx, data)}}

onTagSelect(idx, data){ console.log("======== on tag selected ===========") console.log(idx, data) }

ihsanktmr commented 6 years ago

thanks It worked