在javascript中使用firebase firestore更新函数中的承诺
我正在尝试在完成用户名更新后立即将用户发送到另一个页面。问题是我不知道什么时候调用location.replace函数,或者在这种情况下如何使用承诺。username.value是新用户名在javascript中使用firebase firestore更新函数中的承诺,javascript,firebase,promise,google-cloud-firestore,Javascript,Firebase,Promise,Google Cloud Firestore,我正在尝试在完成用户名更新后立即将用户发送到另一个页面。问题是我不知道什么时候调用location.replace函数,或者在这种情况下如何使用承诺。username.value是新用户名 //don't worry about the if statment, all it is doing is making sure that the element //that stores the new username is not empty if(usernam
//don't worry about the if statment, all it is doing is making sure that the element
//that stores the new username is not empty
if(username.value != ""){
db.collection("users").doc(doc.id).update({
"name": username.value
})
//How can I call this as soon as the username is set?
//location.replace("../pages/homepage.html");
}
你应该在这里找到一些东西: 但你应该这样做:
db.collection("users").doc(doc.id).update({
"name": username.value
})
.then(() => location.replace("../pages/homepage.html"))