Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native react native actionsheet获取选定值_React Native_Actionsheet - Fatal编程技术网

React native react native actionsheet获取选定值

React native react native actionsheet获取选定值,react-native,actionsheet,React Native,Actionsheet,我正在使用react native actionsheet在iOS中显示下拉列表,我能够获取所选索引,但是,我不知道获取所选值的语法是什么 showActionSheet = () => { this.ActionSheet.show() } handlePress = (buttonIndex, option) => { this.setState({ selected: buttonIndex, Region: options}) } <Text s

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

希望这对你有帮助。请不要怀疑。

我不太了解react native actionsheet,但我建立了

react native universal actionsheet更易于定制和控制

这里有一个例子

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