0

我正在使用 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}
    />
4

2 回答 2

0

Make a variable with your option array

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

Pass that variable to your ActionSheet component

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

Inside your handlePress now you can access your selected value as below

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

Hope this helps you. Feel free for doubts.

于 2020-01-19T18:17:47.527 回答
0

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

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

看这里是小吃的一个例子

于 2021-02-22T00:30:17.583 回答