<View style={styles.container}>
<TextInput style={{height: 40, borderColor: 'gray', borderWidth: 1}}
onChangeText={(text) => this.setState({text})}
value={this.state.text}/>
<TouchableHighlight underlayColor='white' onPress={onPressButton}>
<Image style={{width: 50, height: 50}}
source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}}
/>
</TouchableHighlight>
</View>
我想获取View,就像在html中使用'getElementById()'一样,但在React native中,我该怎么做?
答案 0 :(得分:1)
定义ref
:
<View ref={(ref) => {this._myView = ref}} />
然后在您的代码中,您可以像这样访问View
:
this._myView // Do whatever you need here
此处的文档https://facebook.github.io/react/docs/refs-and-the-dom.html#the-ref-callback-attribute