[英]React java script: IF function works only once on button click
所以我使用 react native 和 firebase db。
在注册表单按钮上单击我有创建用户并上传一些信息的功能,如城市电话拉拉拉:
handleSignUp = () => {
Fire.shared.createUser(this.state.email, this.state.password, this.state.name, this.state.avatar, this.state.mobile, this.state.pickerSelection, this.state.errorMessage)
if (this.state.name == "") this.setState({ errorMessage: "Vartotojo vardas privalomas" });
else if (this.state.email == "") this.setState({ errorMessage: "El. pašto adresas privalomas" });
else if (this.state.password == "") this.setState({ errorMessage: "Slaptažodis privalomas" });
else if (this.state.password2 == "") this.setState({ errorMessage: "Pakartokite slaptažodį" });
else if (this.state.city == "") this.setState({ errorMessage: "Telefono nr. privalomas" });
else if (this.state.mobile == "") this.setState({ errorMessage: "Miestas privalomas" });
else if ( this.state.password != this.state.password2) this.setState({ errorMessage: "Slaptažodžiai nesutampa" });
else {
Fire.shared.createUser(this.state.email, this.state.password, this.state.name, this.state.avatar, this.state.mobile, this.state.pickerSelection);
};
};
所以第一次功能有效。 这些 IFS 中的任何一个。 如果我留下空白输入,我会很好地看到错误消息,但是如果我再按一次按钮,它仍然只是在创建用户,即使是空值......就像字面上一样,这一切都只工作一次......
这是我的创建用户功能:
handleSignUp = () => {
Fire.shared.createUser(this.state.email, this.state.password, this.state.name, this.state.avatar, this.state.mobile, this.state.pickerSelection, this.state.errorMessage)
if (this.state.name == "") this.setState({ errorMessage: "Vartotojo vardas privalomas" });
else if (this.state.email == "") this.setState({ errorMessage: "El. pašto adresas privalomas" });
else if (this.state.password == "") this.setState({ errorMessage: "Slaptažodis privalomas" });
else if (this.state.password2 == "") this.setState({ errorMessage: "Pakartokite slaptažodį" });
else if (this.state.city == "") this.setState({ errorMessage: "Telefono nr. privalomas" });
else if (this.state.mobile == "") this.setState({ errorMessage: "Miestas privalomas" });
else if ( this.state.password != this.state.password2) this.setState({ errorMessage: "Slaptažodžiai nesutampa" });
else {
Fire.shared.createUser(this.state.email, this.state.password, this.state.name, this.state.avatar, this.state.mobile, this.state.pickerSelection);
};
};
也许是因为 ASYNC 和 AWAIT? 我只是因为教程而使用,我不确定那是什么。
您调用 Fire.shared.createUser() 两次,第一次是在您的检查之前(因此无论如何它都会创建用户),第二次是您的检查通过时;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.