如何獲取react-native中的元素?getElementById react-native
我的用例是一個登錄屏幕。提交按鈕被按下,現在我想要獲取用戶名和密碼TextInputs的值。
export default class Login extends Component
{
login()
{
//document.getElementById('username'); //run-time error
}
render()
{
return (
<View style={{flex: 1,flexDirection: 'column',justifyContent: 'space-between',margin:10}}>
<View style={{backgroundColor: 'powderblue'}} />
<MyTextField id='user' placeholder="User Name" />
<MyTextField id='pass' placeholder="Password" />
<MyButton onPress={this.login} title='Login'/>
</View>
);
}
}
閱讀https://facebook.github.io/react/docs/forms.html –