在将焦点输入到下一个文本输入后

时间:2018-06-30 04:00:37

标签: javascript react-native

假设我有3个视图,其中包含return try URLEncoding.default.encode(request, with: parameters as! Parameters)

return try JSONEncoding.default.encode(request, with: parameters)

通知TextInput,其中<View style={styles.row}> <TextInput ref={'cell_'+i} maxLength={1} spellCheck={false} style={styles.chewy} onKeyPress={this._onInputFilled} /> </View> <View style={styles.row}> <TextInput ref={'cell_'+i} maxLength={1} spellCheck={false} style={styles.chewy} onKeyPress={this._onInputFilled} /> </View> <View style={styles.row}> <TextInput ref={'cell_'+i} maxLength={1} spellCheck={false} style={styles.chewy} onKeyPress={this._onInputFilled} /> </View> 等于0.2。现在,当我在ref={'cell_'+i}中键入一个字符时,如何聚焦(移动光标)到下一个TextInput即i

1 个答案:

答案 0 :(得分:0)

尝试此代码:

<View style={styles.row}>
    <TextInput
        ref={'cell_'+i}
        maxLength={1}
        spellCheck={false}
        style={styles.chewy}
        onKeyPress={this._onInputFilled}
        onSubmitEditing={() => this.focusNextField('cell_' + (i+1))}
        />
</View>
<View style={styles.row}>
    <TextInput
        ref={'cell_'+i}
        maxLength={1}
        spellCheck={false}
        style={styles.chewy}
        onKeyPress={this._onInputFilled}
        onSubmitEditing={() => this.focusNextField('cell_' + (i+1))}
        />
</View>
<View style={styles.row}>
    <TextInput
        ref={'cell_'+i}
        maxLength={1}
        spellCheck={false}
        style={styles.chewy}
        onKeyPress={this._onInputFilled}
        />
</View>

onSubmitEditing:

focusNextField = nextField => {
   this.refs[nextField].focus();
};