写的一个注册页面,如果账号已存在提示不能注册并清空输入,但是for把if 和else都执行了怎么办?
发布于 4 年前 作者 odu 12054 次浏览 来自 官方Issues

if {

        db.collection('doctors').get({

          success:res=>{

            let doctors=res.data

            for (let i = 0; i < doctors.length; i++{

              const element = doctors[i].AccountNumber;

              if (this.data.AccountNumberInput===doctors[i].AccountNumber{

                wx.hideToast({

                  success: res => {

                    wx.showToast({

                      title: '账号已存在,请重新输入',

                      icon:"none",

                      duration:2000

                    })

                  },

                })

                this.setData({

                  AccountNumberInput:""

                })

              }else{

                wx.showLoading({

                  title: '提交中,请等待',

                  icon:"loading",

                  duration:1000

                })

                this.pushDb()

              }     

            }

          }

        })

    }

 

1 回复

你这里不对吧,this.data.AccountNumberInput这里应该也是一个数组啊 你现在doctors[i].AccountNumber只要有一个和,this.data.AccountNumberInpu相同就执行if,不同就执行else

回到顶部