Javascript React.js,在所有getDownloadURL函数完成后打印一些内容

Javascript React.js,在所有getDownloadURL函数完成后打印一些内容,javascript,reactjs,Javascript,Reactjs,我正在尝试从Firebase获取所有URL。在所有getDownloadURL完成后,我需要打印一些内容。我尝试在storageRef.listAll()之后添加.then(function()){},但是它不起作用。有人能帮我吗?非常感谢你 getAllURL = product => { // Get all the images from the firebase var storage = firebase.storage();

我正在尝试从Firebase获取所有URL。在所有
getDownloadURL
完成后,我需要打印一些内容。我尝试在
storageRef.listAll()
之后添加
.then(function()){}
,但是它不起作用。有人能帮我吗?非常感谢你

  getAllURL = product => {

       // Get all the images from the firebase  
        var storage = firebase.storage();
        var that = this;
        const storageRef =  storage.ref(`image/${product}`)

        storageRef.listAll().then(function(result) { 
          result.items.forEach(function(imageRef) {
                imageRef.getDownloadURL().then(function(url) {    

                  let a = 'a'            
                  that.state.temp3.push(a)
                  console.log("789")

                }).catch(function(error) {});

                console.log("123")
         })
          console.log("456")
       })            
   }

我声明了一个名为
promissions
的变量,并将所有promissions赋值给它。在那之后,我使用了
Promise.all
来等待所有承诺的解决

getAllURL = product => {
  // Get all the images from the firebase
  var storage = firebase.storage();
  var that = this;
  const storageRef = storage.ref(`image/${product}`);

  storageRef.listAll().then(function(result) {
    const promises = result.items.map(function(imageRef) {
      return imageRef
        .getDownloadURL()
        .then(function(url) {
          let a = "a";
          that.state.temp3.push(a);
          console.log("789");
        })
        .catch(function(error) {});
    });

    Promise.all(promises)
      .then((results) => console.log('Promises resolved', results))
  });
};


非常感谢你!