【发布时间】:2016-02-24 09:41:30
【问题描述】:
我在 facebook React Native 页面上找到了示例代码,该页面显示了如何使用 setNativeProp 在单击时清除文本,但我看不到如何使用多个文本框来执行此操作。代码如下:
var App = React.createClass({
clearText() {
this._textInput.setNativeProps({text: ''});
},
render() {
return (
<View style={styles.container}>
<TextInput ref={component => this._textInput = component}
style={styles.textInput} />
<TouchableOpacity onPress={this.clearText}>
<Text>Clear text</Text>
</TouchableOpacity>
</View>
);
}
});
ref 似乎在函数中是固定的,因此将始终以相同的 TextInput 框为目标。如何更改函数以针对我指定的任何 TextInput 框?
【问题讨论】: