Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. function collectres () {
  2. var store ='';
  3. var docRef = db.collection("cities").doc("SF");
  4. docRef.get()
  5. .then(function (doc) {
  6. if (doc.exists) {
  7. console.log("Document data:", doc.data());
  8. store = doc.data();// when referenced outside, it doesnt hold anything.
  9. } else {
  10. // doc.data() will be undefined in this case
  11. console.log("No such document!");
  12. }
  13. })
  14. .catch(function (error) {
  15. console.log("Error getting document:", error);
  16. });
  17. return store; // returns nothing and seems to not notice the assignment.
  18. }
  19.  
  20. user.CollectRes(function(store){
  21. console.log(store.name);
  22. name =store.name;
  23. console.log(name);
  24. // this.setState({name:store.name});
  25. });
  26. console.log(name); // want to be able to reference this outside the callback function. So i can display it on the page.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement