如何将TextInput
值传递给Translation.get(" Replace TextInput Value")
handleKeyPress(e) {
if(e.nativeEvent.key == ' '){
console.log(e.nativeEvent.key);
Translation.get(this.state.text).then(translated => {
console.log(translated);
});
}
}
<TextInput
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
onKeyPress={this._handleKeyPress}
onChangeText={(text) => this.setState({text})}
value={this.state.text}
/>
注意:this.state.text对我不起作用
答案 0 :(得分:0)
如果我理解你的问题,你只需设置新状态:
Translation.get(this.state.text).then(translated => {
this.setState({ text: translated });
});