【发布时间】:2017-02-12 04:53:33
【问题描述】:
我有一个带有defaultValue 设置的<TextInput/> 和一个按钮,它将触发并将<TextInput> 的defaultValue 传递到其他地方。
但是如何将<TextInput/> 的defaultValue 传递给<TouchableHighlight/> 的onPress 方法呢?
这就是我想要达到的目标:
changeName(text) {
this.setState({nameNow: text}) //How can I immediately set the defaultValue='PassMeIn' to nameNow? Because this method would never be called unless text is changed within TextInput
}
sendOff() {
//Would like to access the defaultValue='PassMeIn' here whenever sendOff() is called. How can I?
}
render() {
return (
<View>
<TextInput
defaultValue='PassMeIn'
onChange={this.changeName}
value={this.state.nameNow}
/>
<TouchableHighlight onPress={this.sendOff}/>
<Text>Button</Text>
</TouchableHighlight>
</View>
)
}
【问题讨论】:
标签: javascript css react-native textinput jsx