undefined не является объектом (оценка newText.split) - PullRequest
0 голосов
/ 21 ноября 2018

У меня ошибка, которую я не могу решить.Когда я запускаю этот код, я получаю undefined не объект (оценивающий newText.split).

  <View style={fieldContainerStyle}>
                <TextInput
                    {...inputProps}
                    {...input}
                    onSelectionChange={(event) => this.setState({ cursorPosition: event.nativeEvent.selection, selection: event.nativeEvent.selection })}
                    onSubmitEditing={() => {
                        const { query, cursorPosition } = this.state;
                        let newText = query;
                        const ar = newText.split('');
                        ar.splice(cursorPosition.start, 0, '\n');
                        newText = ar.join('');

                        if (cursorPosition.start === query.length && query.endsWith('\n')) {
                            this.props.input.onChange(newText)
                        } else if (this.state.allowEditing) {
                            this.props.input.onChange(newText)
                            this.setState({
                                selection: {
                                    start: cursorPosition.start + 1,
                                    end: cursorPosition.end + 1
                                },
                                allowEditing: !this.state.allowEditing
                            });
                        }
                    }}
                    multiline={true}
                    numberOfLines={3}
                    underlineColorAndroid='transparent'
                    blurOnSubmit={false}
                    returnKeyType='none'
                    style={combinedInputStyle}
                />
            </View>

Может кто-нибудь увидеть проблему?

1 Ответ

0 голосов
/ 21 ноября 2018

Ошибка и ее место указывают на то, что вы пытаетесь сделать undefined.split('') - проверьте this.state.query, похоже, оно не установлено:

 onSelectionChange={(event) => this.setState({ cursorPosition: event.nativeEvent.selection, selection: event.nativeEvent.selection })}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...