【问题标题】:Input, unable to retrieve input value React Native输入,无法检索输入值 React Native
【发布时间】:2016-01-21 13:30:39
【问题描述】:
 Login(){
    alert(this.state.username);
    this.props.navigator.push({
        component: MainActivity
    })
    }



render() {
    return<View style={styles.loginView}>
        <Image style={styles.image} source={require('./Ionic.png')}/>
        <Text style={styles.loginText}>Chat System</Text>
        <TextInput style={styles.usernameText} placeholder="username" placeholderTextColor="black" onChangeText={(text) => this.setState({username: text})} />
        <TextInput style={styles.passwordText} placeholder="password" placeholderTextColor="black" onChangeText={(text) => this.setState({password: text})}  onSubmitEditing={this.Login} secureTextEntry/>
        <TouchableWithoutFeedback onPress={this.Login}><View style={styles.loginButton}> <Text style={styles.loginButtonText}>Sign In</Text></View></TouchableWithoutFeedback>
        <TouchableWithoutFeedback><View style={styles.signUpButton}><Text style={styles.signUpButtonText}>Sign Up</Text></View></TouchableWithoutFeedback>
        <TouchableWithoutFeedback><View><Text style={styles.forgetPasswordText}>Forgot password?</Text></View></TouchableWithoutFeedback>
    </View>

}

我需要获取用户名和密码输入的值,在登录方法中,点击登录或输入密码后按回车。

我目前收到this error while running in iOS

【问题讨论】:

    标签: javascript ios reactjs react-native


    【解决方案1】:

    我试过你的代码,显然那里有一个空格:

    <TouchableWithoutFeedback onPress={this.Login}><View style={styles.loginButton}> <Text style={styles.loginButtonText}>Sign In</Text></View></TouchableWithoutFeedback>
    

    导致错误。

    【讨论】:

    • 感谢您的回复。它确实奏效了。你能帮我为什么我无法从我的登录方法中的用户名输入字段中获取变量。
    • @Smit 查看我的另一个答案来解决您的问题。
    • 感谢您的回复。可以给我解释一下吗?还是将 cmets 放在 repo 上?谢谢
    【解决方案2】:

    这是一个工作示例:https://rnplay.org/apps/HVoVfw

    你执行Login错了,正确的方法是:

    <TouchableWithoutFeedback onPress={() => this.Login()}>
      <Text>Sign In</Text>
    </TouchableWithoutFeedback>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-07
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      相关资源
      最近更新 更多