【发布时间】:2017-02-24 10:40:21
【问题描述】:
使用 React-Native,我有一个从 TextInput 扩展的自定义组件,如下所示:
TextBox.js
...
render() {
return (
<TextInput
{...this.props}
style={styles.textBox}/>
);
}
...
MyScene.js(导入 TextBox.js)
...
render() {
render(
<View>
<TextBox
rel='MyFirstInput'
returnKeyType={'next'}
onSubmitEditing={(event) => { this.refs.MySecondInput.focus(); }}/>
<TextBox
ref='MySecondInput'/>
</View>
);
}
当我构建应用程序并在关注 MyFirstInput 时按键盘上的下一步时,我希望 MySecondInput 成为焦点,但我得到了错误:
_this2.refs.MySecondInput.focus is not a function
错误可能是什么?和this的范围有关吗?谢谢。
【问题讨论】:
标签: javascript reactjs react-native ecmascript-6