簡體   English   中英

react-native-actionsheet 獲取選定的值

[英]react-native-actionsheet get selected value

我正在使用 react-native-actionsheet 在 iOS 中顯示下拉列表,我能夠獲取所選索引,但是,我也不知道獲取所選值的語法是什么。

showActionSheet = () => {
  this.ActionSheet.show()
}

handlePress = (buttonIndex,  option) => {
  this.setState({ selected: buttonIndex, Region: options})
}

     <Text style={styles.inputfields} onPress={this.showActionSheet}>Region</Text>
        <ActionSheet
      ref={o => this.ActionSheet = o}
      title={'Region'}
      options={['North', 'South', 'East', 'West', 'Cancel']}
      cancelButtonIndex={5}
      selectedValue={this.state.Region}
      value={this.state.Region}
      onPress={this.handlePress}
    />

使用您的選項數組創建一個變量

const options = ['AUH', 'DXB', 'NE', 'WR', 'AAN', 'Cancel']

將該變量傳遞給ActionSheet組件

<ActionSheet
  ref={o => (this.ActionSheet = o)}
  title={"Region"}
  options={options}
  cancelButtonIndex={5}
  selectedValue={this.state.Region}
  value={this.state.Region}
  onPress={this.handlePress}
/>;

現在在您的handlePress您可以訪問您選擇的值,如下所示

handlePress = buttonIndex => {
  this.setState({
    selected: buttonIndex,
    Region: options[buttonIndex]
  });
};

希望這對你有幫助。 如有疑問,請放心。

好吧,我真的不知道react-native-actionsheet但我構建

react-native-universal-actionsheet更容易定制和控制。

見這里是小吃的一個例子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM