React Native - 专注于下一个TextInput字段

时间:2016-10-14 15:24:32

标签: javascript reactjs react-native

我在尝试关注下一个字段时获得undefined is not a function (evaluating '_this2._password.focus()')

<View style={{ height: h * .13, width: w }}>
   <Kohana style={[styles.input, { backgroundColor: '#f9f5ed' }]}
           label={'Email'}
           onChangeText={(email) => this.email = email}
           iconClass={MaterialsIcon}
           iconName={'email'}
           iconColor={'#ddd'}
           iconColor={'#f4d29a'}
           keyboardType={'email-address'}
           labelStyle={[styles.inputLabel, { color: '#91627b' }]}
           inputStyle={[styles.inputInput, { color: '#91627b' }]}
           blurOnSubmit={false}
           returnKeyType={"next"}
           onSubmitEditing={(e) => {this._password.focus()}} />
</View>
<View style={{ height: h * .13, width: w }}>
   <Kohana
           style={[styles.input, { backgroundColor: '#f9f5ed' }]}
           ref={(ref) => this._password = ref}
           label={'Password'}
           onChangeText={(password) => this.password = password}
           secureTextEntry={true}
           iconClass={MaterialsIcon}
           iconName={'lock'}
           iconColor={'#ddd'}
           iconColor={'#f4d29a'}
           blurOnSubmit={true}
           labelStyle={[styles.inputLabel, { color: '#91627b' }]}
           inputStyle={[styles.inputInput, { color: '#91627b' }]}/>
</View>

我尝试了其他解决方案,一个是ref一个字符串,然后将其称为this.refs._refName.focus(),另一个来自Facebook,您可以在其中创建refs连续整数 - [this][1],但它们都不起作用。

1 个答案:

答案 0 :(得分:1)

Focus是TextInput组件的一种方法。但是,您可以在Kohana组件中添加自定义焦点方法,并调用组件中存在的TextInput焦点。您必须添加对TextInput的引用才能执行此操作。

请在此处查看我的回答:undefined exception while calling focus method on TextInput ref

相关问题