【发布时间】:2019-08-08 10:17:16
【问题描述】:
我想显示在 react native 中选择下拉项时应该显示的文本输入字段
我使用简单的逻辑。我创建了一个函数,试图将选定的值传递给函数,但找不到选定的项目
export class ThirdPage extends Component{
static navigationOptions ={
title:"Register",
header:null
};
state = {
// user:'',
username: '',
phn: '',
address:'',
password:'',
// isLoggingIn: false,
text:''
};
displayacoountForm = (text)=>{
if({text} === "user"){
return <TextInput style={[styles.input]}
placeholder="Enter your phone number"
// underlineColorAndroid="transparent"
numberOfLines = {1}
onChangeText={(phn) => this.setState({ phn })}
/>
}
if({text} === "doctor"){
return <TextInput style={[styles.input]}
placeholder="Enter your password"
secureTextEntry={true}
// underlineColorAndroid="transparent"
numberOfLines = {1}
onChangeText={(password) => this.setState({ password })}
/>
}
if({text} === "clinic"){
<TextInput style={[styles.input]}
placeholder="Enter your phone clinic"
// underlineColorAndroid="transparent"
numberOfLines = {1}
onChangeText={(phn) => this.setState({ phn })}
/>
}
}
render(){
const data = [["user", "doctor", "clinic"]];
return(
<View style={[styles.wholecontainer,styles.verticalFlex,styles.backgroundColor1]}>
<Image
style={[styles.container1,styles.backgroundColor1,styles.position1]}
source={require('Finalapp/Images/createacc.png')}
/>
<Text style={[styles.headText,styles.position2]}>Create Your Account</Text>
<ScrollView style={[styles.backgroundColor1]}>
<View style={[styles.container2]}>
<TextInput style={[styles.input]}
placeholder="Enter your Name"
// underlineColorAndroid="transparent"
numberOfLines = {1}
onChangeText={(username) => this.setState({ username })}
/>
<TextInput style={[styles.input]}
placeholder="Enter your address"
// underlineColorAndroid="transparent"
numberOfLines = {1}
onChangeText={(address) => this.setState({address})}
/>
<TextInput style={[styles.input]}
placeholder="Enter your phone number"
// underlineColorAndroid="transparent"
numberOfLines = {1}
onChangeText={(phn) => this.setState({ phn })}
/>
<TextInput style={[styles.input]}
placeholder="Enter your password"
secureTextEntry={true}
// underlineColorAndroid="transparent"
numberOfLines = {1}
onChangeText={(password) => this.setState({ password })}
/>
<View style={[styles.container3]}>
<DropdownMenu
// style={[styles.container4]}
bgColor={'white'}
tintColor={'#666666'}
activityTintColor={'green'}
// arrowImg={}
// checkImage={}
// optionTextStyle={{color: '#333333'}}
// titleStyle={{color: '#333333'}}
// maxHeight={300}
handler={(selection, row) => this.setState({text: data[selection][row]})}
data={data}
>
<View style={[styles.backgroundColor1]}>
{this.displayacoountForm({this.state.text})}
</View>
</DropdownMenu>
</View>
<View style={[styles.button2]}>
<Button
// class="button"
onPress={()=>this.props.navigation.navigate('Login')}
title="Submit"
color="#29468f"
/>
</View>
</View>
</ScrollView>
</View>
)};
}
【问题讨论】:
-
您使用的是哪个下拉菜单库?
-
"react-native-dropdown-menu": "^2.0.0",
标签: android reactjs react-native mobile-development