如何获取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 –