react-native - 选择选项后如何禁用反应本机选择器
问题描述
我想从下拉列表中选择一个选项后立即禁用(我不想选择任何内容)选择器。这里是选择器,
<View style={editProfileStyle.pickerView}>
<Picker
style={{
...Platform.select({
android: {
color: "#000"
}
})
}}
enabled={true}
selectedValue={this.state.Qualification}
onValueChange={this.updateState}
mode="dropdown"
itemStyle={{ height: 80, color: "#000000" }}
>
{this.state.options.map((item, index) => {
return <Picker.Item value={item} key={index} label={item} />;
})}
</Picker>
</View>
如果找到解决方案将有很大帮助!
解决方案
您可以使用 enabled props , enabled ={this.state.enabled} ,当用户选择日期时,调用 setState 并将启用状态切换为 false。请记住,启用的道具仅适用于 android。这是一个例子:
constructor(props) {
super(props);
this.state = {
enabled: true // Enabled by default , you can change it
};
// inside your updateState function call : this.setState({enabled:false})
// if you dont already defined updateState
// updateState = () =>{ this.setState({enabled:false})
<View style={editProfileStyle.pickerView}>
<Picker
style={{
...Platform.select({
android: {
color: "#000"
}
})
}}
enabled={this.state.enabled}
selectedValue={this.state.Qualification}
onValueChange={this.updateState}
mode="dropdown"
itemStyle={{ height: 80, color: "#000000" }}
>
{this.state.options.map((item, index) => {
return <Picker.Item value={item} key={index} label={item} />;
})}
</Picker>
</View>
推荐阅读
- laravel - 模型关系
- ios - ImageView 上的平滑线条
- java - Drawing an edge around an arc using SWT
- c++ - 如何在 C++ 中将不同的数据类型转换为字节?
- google-chrome - Chrome 开发工具跟踪文件的完整事件中“dur”的总和
- javascript - 能够在primeng日历上选择超出最小/最大日期的日期
- javascript - Grunt package.json:如何将依赖项安装到公共子文件夹?
- javascript - JS函数更改时某些文本扭曲
- c# - 我必须将字符串转换为双精度吗?
- c# - 在 TreeView 的 HierarchialDataTemplate 中动态更改 Itemsource 的集合