简体   繁体   中英

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?

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)?

     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. Just put the code you want to execute after get() completes inside the function you're already passing to then() in your code sample.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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