doc:https://facebook.github.io/react-native/docs/picker
构造函数:
constructor(props) {
super(props);
this.state = {
showPass: true,
press: false,
email: "",
age: 0,
sexe:"",
password: "",
confirmPass: ""
}
}
JSX:
<Picker
selectedValue={this.state.sexe}
onValueChange={(value) => {this.setState({sexe: value})}}>
<Picker.Item label="Homme" value="homme" />
<Picker.Item label="Femme" value="femme" />
</Picker>
问题:我不知道为什么this.state.sexe不受影响
答案 0 :(得分:1)
您应该在状态上指定默认选择,然后只有onValueChange才能触发
尝试以下代码
constructor(props) {
super(props);
this.state = {
showPass: true,
press: false,
email: "",
age: 0,
sexe:"homme",
password: "",
confirmPass: ""
}
}
和JSX
<Picker
selectedValue={this.state.sexe}
onValueChange={(value) => {this.setState({sexe: value})}}>
<Picker.Item label="Homme" value="homme" />
<Picker.Item label="Femme" value="femme" />
</Picker>