简体   繁体   English

firestore get方法完成后执行代码

[英]Execute Code after firestore get method is finished

I know that using java (android) you can execute code after the get method is finished, is that also possible when using javascript? 我知道使用Java(android)您可以在get方法完成后执行代码,使用JavaScript也是可行的吗?

Here is my code: 这是我的代码:

      mColRef.get().then(function(querySnapshot){
          querySnapshot.forEach(function(doc) {
              console.log(doc.id);
          });
      });

Can I do something like this? 我可以做这样的事情吗? Or how would you code something like this for web (javascript)? 或者,您将如何为网络(javascript)编写类似的代码?

     mColRef.get().then(function(querySnapshot){
          querySnapshot.forEach(function(doc) {
              console.log(doc.id);
          });
      }).OnCompleteListener(new OncompleteListener ....

Thanks for your help! 谢谢你的帮助!

It looks like you're overcomplicating things. 看来您太复杂了。 The use of then() on a promise in JavaScript serves the same purpose as the use of an OnCompleteListener on a Task object in Android. 在JavaScript中对promise使用then()的目的与在Android中对Task对象使用OnCompleteListener目的相同。 Just put the code you want to execute after get() completes inside the function you're already passing to then() in your code sample. 只需将要执行的代码放入get()完成之后的函数中,该函数已经传递给代码示例中的then()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM