【发布时间】:2017-12-06 14:29:42
【问题描述】:
每当我从picker 中选择一个项目并使用alert 显示所选项目时,我都会尝试调用function。
这就是我正在做的事情:-
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, TextInput, View, Alert, Button,Platform,ActivityIndicator, Text, Picker, ScrollView } from 'react-native';
export default class FirstProject extends Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
throttlemode:'',
}
}
GetSelectedThrottleModeItem=(throttlemode)=>{
Alert.alert(this.state.throttlemode)
}
render() {
return (
<View style={styles.MainContainerAddCamp}>
<Text style={{fontSize: 12}}> Throttle Mode</Text>
<Picker style={styles.PickerStyleClass}
selectedValue={this.state.throttlemode}
onValueChange={(throttlemodeValue, throttlemodeIndex) => this.GetSelectedThrottleModeItem(this.setState({throttlemode:throttlemodeValue}))}>
<Picker.Item label="Asap" value="asap" />
<Picker.Item label="Even" value="even" />
</Picker>
</View>
);
}
}
const styles = StyleSheet.create({
MainContainerAddCamp :{
flex:1,
margin: 10,
paddingTop: (Platform.OS === 'ios') ? 20 : 20,
padding: 5,
},
TextInputStyleClass: {
textAlign: 'left',
paddingLeft: 7,
marginBottom: 7,
height: 40,
borderWidth: 1,
borderColor: '#00BCD4',
},
PickerStyleClass:{
backgroundColor:'#87ceeb',
paddingLeft: 7,
marginBottom: 7,
height: 40,
borderWidth: 1,
borderColor: '#FF5722',
}
});
此代码显示先前选择的值。我怎样才能让它显示当前选定的值。
请提出我错过的地方。
【问题讨论】:
标签: javascript android reactjs react-native