我正在使用类外部的自定义浮动文本标签,我想在其中设置状态。请问我该怎么做
当我单击按钮时,我有两个浮动文本字段,我想将状态设置为输入文本字段中输入的值。
错误是得到是
this.setState 不是函数
const TextfieldWithFloatingLabel_Card = MKTextField.textfieldWithFloatingLabel()
.withPlaceholder(strings.nineDigitCardNumber)
.withStyle(styles.textfieldWithFloatingLabel)
.withTextInputStyle({ flex: 1 })
.withFloatingLabelFont({
fontSize: 12,
fontWeight: '200',
color: colors.primaryColor
})
.withKeyboardType('numeric')
.withOnEndEditing(e => {
this.setState({ cardDigits: e.nativeEvent.text });
console.log('EndEditing', e.nativeEvent.text);
})
.build();
const TextfieldWithFloatingLabel_NationalId = MKTextField.textfieldWithFloatingLabel()
.withPlaceholder(strings.nationalIdNumber)
.withStyle(styles.textfieldWithFloatingLabel)
.withTextInputStyle({ flex: 1 })
.withFloatingLabelFont({
fontSize: 12,
fontWeight: '200',
color: colors.primaryColor
})
.withKeyboardType('numeric')
.withOnEndEditing(e => {
this.setState({ nationalIdNumber: e.nativeEvent.text });
console.log('EndEditing', e.nativeEvent.text);
})
.build();
class Login extends React.Component {
constructor(props) {
super(props);
this.state = {
cardDigits: '',
IdNumber: ''
};
}
render() {
//console.log('rovers - ' + JSON.stringify(this.state.rovers))
return (
<ScrollView style={styles.mainContainer}>
<TextfieldWithFloatingLabel_Card ref="tiNumber" />
<TextfieldWithFloatingLabel_NationalId ref="tiNationalId" />
<TouchableOpacity
title="Transactions"
style={{
height: 60,
backgroundColor: '#673fb4',
marginTop: 20,
alignItems: 'center',
justifyContent: 'center'
}}
onPress={() => {
consoleLog(
'cardnum : ' +
this.state.cardDigits +
' national id - ' +
this.state.IdNumber
);
}}
>
<CommonText style={{ color: 'white' }}>
{strings.signInLower}
</CommonText>
</TouchableOpacity>
</ScrollView>
);
}
}
谢谢R