javascript - Use data from two locations in Firebase, reading data simultaneously -
i want read data 2 database locations, , use these bits of data in function. way doing this:
firebase.database().ref('/data/').once('value').then(function(data1) { firebase.database().ref('/datatwo/').once('value').then(function(data2) { //here can use data1.val() , data2.val() }); });
however, understand begins reading /otherdata
after first piece of data has finished retrieving. there way simultaneously download these 2 pieces of data , use them in function 1 both complete?
thanks
use promise.all()
:
promise.all([ firebase.database().ref('/data/').once('value'), firebase.database().ref('/datatwo/').once('value') ]).then(function(results) { var data1 = results[0], data2 = results[1]; //here can use data1.val() , data2.val() });
Comments
Post a Comment