Javascript toUpperCase()在react native中不起作用,它的第一个字母重复了两次

Javascript toUpperCase()在react native中不起作用,它的第一个字母重复了两次,javascript,reactjs,react-native,Javascript,Reactjs,React Native,这是我的代码,有3个输入字段,在uniqueIdNo中,每当我必须输入时,它应该自动转换为大写。我使用的是toUpperCase()函数,它也会转换为大写,但是 如果我写ab两个字母,它的未来AAB意味着无论我输入的第一个字母是什么,加上它,未来两次 this.state={ firstName: props.firstName || '', lastName: props.lastName || '', uniqueIdNo:props.uniqueIdNo || '', }

这是我的代码,有3个输入字段,在uniqueIdNo中,每当我必须输入时,它应该自动转换为大写。我使用的是toUpperCase()函数,它也会转换为大写,但是 如果我写ab两个字母,它的未来AAB意味着无论我输入的第一个字母是什么,加上它,未来两次

this.state={
  firstName: props.firstName || '',
  lastName: props.lastName || '',
  uniqueIdNo:props.uniqueIdNo || '',
}

this.onChangeText(text,“FN”)}
/>
this.onChangeText(text,“LN”)}
/>
this.onChangeText(text,“UIN”)}
/>

嘿,你可以检查我的世博快餐链接,我找不到错误,请检查:

代码如下:

import * as React from 'react';
import { Text, View, StyleSheet,TextInput } from 'react-native';
export default class App extends React.Component {

constructor(props){
  super(props)
this.state={
  firstName:'',
  lastName:  '',
  uniqueIdNo: '',
}
}

onChangeText = async (text, identifier) => {
  if (identifier === "FN") {
    this.setState({
      firstName: text
    });
  } else if (identifier === "LN") {
    this.setState({
      lastName: text
    });
  } else if (identifier === "UIN") {
    this.setState({
      uniqueIdNo: text.toUpperCase()
    });
  }
};

  render() {
    let {firstName,lastName,uniqueIdNo} = this.state;
    return (
      <View style={styles.container}>
       <View style={{ borderColor: "#00fff", borderBottomWidth: 0.6 }}>
  <TextInput
    value={firstName}
    keyboardType="default"
    onChangeText={text => this.onChangeText(text, "FN")}
  />
</View>
<View style={{ borderColor: "#00fff", borderBottomWidth: 0.6 }}>
  <TextInput
    value={lastName}
    keyboardType="default"
    onChangeText={text => this.onChangeText(text, "LN")}
  />
</View>
<View style={{ borderColor: "#00fff", borderBottomWidth: 0.6 }}>
  <TextInput
    value={uniqueIdNo}
    onChangeText={text => this.onChangeText(text, "UIN")}
  />
</View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
  paragraph: {
    margin: 24,
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'center',
  },
});
import*as React from'React';
从“react native”导入{Text,View,StyleSheet,TextInput};
导出默认类App扩展React.Component{
建造师(道具){
超级(道具)
这个州={
名字:'',
姓氏:“”,
唯一编号:“”,
}
}
onChangeText=async(文本,标识符)=>{
如果(标识符=“FN”){
这是我的国家({
名字:text
});
}else if(标识符==“LN”){
这是我的国家({
姓氏:text
});
}else if(标识符==“UIN”){
这是我的国家({
uniqueIdNo:text.toUpperCase()
});
}
};
render(){
让{firstName,lastName,uniqueIdNo}=this.state;
返回(
this.onChangeText(text,“FN”)}
/>
this.onChangeText(text,“LN”)}
/>
this.onChangeText(text,“UIN”)}
/>
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
为内容辩护:“中心”,
背景颜色:“#ecf0f1”,
填充:8,
},
第段:{
差额:24,
尺码:18,
fontWeight:'粗体',
textAlign:'中心',
},
});

希望能有帮助。有疑问请放心

嘿,你可以查看我的世博快餐链接,我找不到错误,请检查:

代码如下:

import * as React from 'react';
import { Text, View, StyleSheet,TextInput } from 'react-native';
export default class App extends React.Component {

constructor(props){
  super(props)
this.state={
  firstName:'',
  lastName:  '',
  uniqueIdNo: '',
}
}

onChangeText = async (text, identifier) => {
  if (identifier === "FN") {
    this.setState({
      firstName: text
    });
  } else if (identifier === "LN") {
    this.setState({
      lastName: text
    });
  } else if (identifier === "UIN") {
    this.setState({
      uniqueIdNo: text.toUpperCase()
    });
  }
};

  render() {
    let {firstName,lastName,uniqueIdNo} = this.state;
    return (
      <View style={styles.container}>
       <View style={{ borderColor: "#00fff", borderBottomWidth: 0.6 }}>
  <TextInput
    value={firstName}
    keyboardType="default"
    onChangeText={text => this.onChangeText(text, "FN")}
  />
</View>
<View style={{ borderColor: "#00fff", borderBottomWidth: 0.6 }}>
  <TextInput
    value={lastName}
    keyboardType="default"
    onChangeText={text => this.onChangeText(text, "LN")}
  />
</View>
<View style={{ borderColor: "#00fff", borderBottomWidth: 0.6 }}>
  <TextInput
    value={uniqueIdNo}
    onChangeText={text => this.onChangeText(text, "UIN")}
  />
</View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
  paragraph: {
    margin: 24,
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'center',
  },
});
import*as React from'React';
从“react native”导入{Text,View,StyleSheet,TextInput};
导出默认类App扩展React.Component{
建造师(道具){
超级(道具)
这个州={
名字:'',
姓氏:“”,
唯一编号:“”,
}
}
onChangeText=async(文本,标识符)=>{
如果(标识符=“FN”){
这是我的国家({
名字:text
});
}else if(标识符==“LN”){
这是我的国家({
姓氏:text
});
}else if(标识符==“UIN”){
这是我的国家({
uniqueIdNo:text.toUpperCase()
});
}
};
render(){
让{firstName,lastName,uniqueIdNo}=this.state;
返回(
this.onChangeText(text,“FN”)}
/>
this.onChangeText(text,“LN”)}
/>
this.onChangeText(text,“UIN”)}
/>
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
为内容辩护:“中心”,
背景颜色:“#ecf0f1”,
填充:8,
},
第段:{
差额:24,
尺码:18,
fontWeight:'粗体',
textAlign:'中心',
},
});
希望能有帮助。不要怀疑

试试这个:

if (identifier === "UIN") {
var uppercasetext = text.toUpperCase();//To convert Upper Case
this.setState({
  uniqueIdNo: uppercasetext    
});
试试这个:

if (identifier === "UIN") {
var uppercasetext = text.toUpperCase();//To convert Upper Case
this.setState({
  uniqueIdNo: uppercasetext    
});

输入有一个名为autoCapitalize的属性,可用于大写问题

   <Input
    autoCapitalize="sentences"
  />


有一个名为autoCapitalize的属性可用于输入大写字母

   <Input
    autoCapitalize="sentences"
  />


我想这和我在问题中写的代码是一样的,不起作用,但你在世博会上检查过了吗?你找到错误了吗?是的,有问题。。它增加了额外的刺痛。。。我猜toUppercase在打字时不能正常工作,但在哪里呢?我猜这和我之前写的代码是一样的,不起作用,但你在世博会登记了吗?你找到错误了吗?是的,有问题。。它增加了额外的刺痛。。。我猜toUppercase在打字时不能正常工作,但在哪里呢?我找不到你为什么把
async
放在
onChangeText()
函数上?你为什么把
async
放在
onChangeText()函数上?