有没有办法在用户点击它之前显示 react 原生选择器的占位符。这个想法是有一个选择器,上面写着“国籍”,一旦你点击并选择你的国家,它就会呈现国家。我想在没有“国籍”作为选择器中的可用选项的情况下执行此操作。
最佳答案
您可以改用 native-base 的选择器。
1. 运行:
npm i native-base --save
2. 导入为:
import {Picker} from 'native-base';
3. 用作:
<Picker
placeholder="Start Year" // yipeee, placeholder
iosIcon={<Ionicons name="ios-arrow-down" />} // right icon
selectedValue={this.state.selected_id} // your selected item value
style={{
// your styles
}}
// onValueChange={this.onValueChange.bind(this)} // use it the way it suites you
onValueChange={(v)=>this.setState({selected_id:v})} // use it the way it suites you
>
<Picker.Item label="Val 1" value="1" />
<Picker.Item label="Val 2" value="2" />
<Picker.Item label="Val 3" value="3" />
</Picker>
关于react-native - 有一个占位符用于 react 原生选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37440464/