Javascript React Native:如何在方法中触发TextInput实例模糊?
我点击导航器上的一个按钮,当前屏幕的一个文本输入就是焦点。 我需要设置TextInput的实例模糊,以触发Javascript React Native:如何在方法中触发TextInput实例模糊?,javascript,react-native,Javascript,React Native,我点击导航器上的一个按钮,当前屏幕的一个文本输入就是焦点。 我需要设置TextInput的实例模糊,以触发textChange函数来执行某些操作 在我的例子中,TextInput的光标一直在闪烁 refs.username.blur()不起作用 我的代码: class UploadRecordII extends Component{ static navigationOptions = ({ navigation, screenProps }) => ({ headerRi
textChange
函数来执行某些操作
在我的例子中,TextInput的光标一直在闪烁
refs.username.blur()
不起作用
我的代码:
class UploadRecordII extends Component{
static navigationOptions = ({ navigation, screenProps }) => ({
headerRight: (<Button containerStyle={{marginRight: 12,}} onPress={ UploadRecordII.onSubmit}>
<Text style={{color: 'white',fontSize: 18,}}>next</Text>
</Button>),
});
.....
static onSubmit() {
let that = UploadRecordII.instance;
debugger;
that.refs.username.blur();
debugger;
that.props.commitCreateRecordUpdate(that.refs.username._lastNativeText,that.imageList)
that.props.navigation.navigate('Record3');
}
...... in render(){
....
<TextInput ref = 'username' placeholder='' editable = {true} maxLength = {500}
keyboardType='default' multiline={true}
style={styles.input} underlineColorAndroid='rgba(0,0,0,0)'
onBlur={ ()=> this.textChange()}
clearButtonMode='always' placeholderTextColor='#D6D0D8'></TextInput>
...
}
类UploadRecordII扩展组件{
静态导航选项=({navigation,screenProps})=>({
头灯:(
下一个
),
});
.....
静态onSubmit(){
让它=UploadRecordII.instance;
调试器;
that.refs.username.blur();
调试器;
that.props.commitCreateRecordUpdate(that.refs.username.\u lastNativeText,that.imageList)
that.props.navigation.navigate('Record3');
}
…在render()中{
....
this.textChange()}
clearButtonMode='always'占位符文本颜色='#D6D0D8'>
...
}
参考不再像预期的那样作为字符串工作。您需要定义您的参考,例如
class UploadRecordII extends Component {
constructor(props) {
super(props);
this.usernameInput = null;
}
onSubmit() {
this.usernameInput.blur();
}
render() {
return (
<TextInput ref={(input) => this.usernameInput = input} ... />
)
}
}
类UploadRecordII扩展组件{
建造师(道具){
超级(道具);
this.usernameInput=null;
}
onSubmit(){
this.usernameInput.blur();
}
render(){
返回(
this.usernameInput=input}…/>
)
}
}
使用onChange
设置this.description
,然后在按下按钮的方法中引用this.description
有什么问题?另外,请复制您的代码,而不是使用屏幕截图。@BenjaminCommet我再次编辑此问题。我的代码是更改。非常感谢!我已经根据您的建议修改了代码。this.usernameInput.blur()代码>也不起作用。