我的组件是:
class TextInputComp extends Component {
constructor(props){
super();
this.state = { thetext: '' }
}
submitText = (text) => {
Alert.alert("Text Submitted!", text);
}
render() {
const renData = this.props.people((data, index) => {
return (
<View key={index} style={styles.card}>
<Text style={styles.names}> ID: {data.id} - Name: {data.name} </Text>
<TouchableOpacity
onPress={()=>this.refs.MyBox.focus()} >
<Text>Open</Text>
</TouchableOpacity>
</View>
)
});
return (
<View style={mystyles1.container}>
{renData}
<View>
<TextInput
ref='MyBox'
style={{height: 40}}
onChangeText={(thetext) => this.setState({thetext})}
/>
<TouchableOpacity
onPress = { () => this.submitText(this.state.thetext) }>
<Text style = {styles.ButtonText}> Submit </Text>
</TouchableOpacity>
</View>
</View>
);
}
}
单击时,我可以显示来自{redData}
和的数据。我想将一个值传递给. 假设我想通过,所以当打开时,我希望已经在 的开头,这样我就可以将它传递给。focus
TextInput
Open
TextInput
data.name
onPress
Open
data.name
TextInput
this.state.thetext
我怎样才能做到这一点?非常感谢。