最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting value selected when using react-native-modal-dropdown - Stack Overflow

programmeradmin1浏览0评论

I am storing user text input into states like so

<TextInput
    placeholder = "Hello"
    onChangeText = {(text) => this.setState({greeting: text})}
/>

I want to do a similar thing using react-native-modal-dropdown.

<ModalDropdown
    style = {styles.enterSearch}
    options = {this.state.gasOptions}
    onSelect {(renderButtonText) => this.setState({gas: renderButtonText})}
/>

With this code I can select what option I want but I cannot find a way to get the value of the text option selected.

Any help would be great.

I am storing user text input into states like so

<TextInput
    placeholder = "Hello"
    onChangeText = {(text) => this.setState({greeting: text})}
/>

I want to do a similar thing using react-native-modal-dropdown.

<ModalDropdown
    style = {styles.enterSearch}
    options = {this.state.gasOptions}
    onSelect {(renderButtonText) => this.setState({gas: renderButtonText})}
/>

With this code I can select what option I want but I cannot find a way to get the value of the text option selected.

Any help would be great.

Share Improve this question edited Jul 10, 2018 at 21:22 paulgio asked Jul 10, 2018 at 21:04 paulgiopaulgio 7222 gold badges8 silver badges23 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

For some reason you have to put String in front of the value for it to actually read it correctly. This took me a while to figure out so I hope it helps someone else out.

 <ModalDropdown
        style = {styles.enterSearch}
        options = {this.state.gasOptions}
        onSelect {(value) => this.setState({gas: (String(this.state.gasOptions[value]))})}
    />
发布评论

评论列表(0)

  1. 暂无评论