【问题标题】:Get documents from Firebase but if they are already showing - dont show again从 Firebase 获取文档,但如果它们已经显示 - 不再显示
【发布时间】:2022-01-02 14:43:33
【问题描述】:

我有以下代码:

const getFromFirebase = () => {
    //1.
    let storageRef = storage.ref(`${user1}/${currentItem.id}`);
    //2.
    storageRef.listAll().then(function (res) {
        //3.
        res.items.forEach((imageRef) => {
          imageRef.getDownloadURL().then((url) => {
              //4.
              if (allImages.indexOf(url) === -1) {
              setImages((allImages) => [...allImages, ({Test : url, Test2 : imageRef.name})]);
              }
          });
        });
        
      })
      .catch(function (error) {
        console.log(error);
      });
  };

我在 onclick 选项卡上调用此函数 - 它的工作原理是显示文档,但如果我再次单击选项卡,它只会重复自身 - 我如何运行检查是否所有文档都已显示以不加倍?

【问题讨论】:

    标签: javascript firebase firebase-storage


    【解决方案1】:

    使用回调函数,你没有输入一个空数组。

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-15
    • 1970-01-01
    • 2021-02-08
    • 2020-08-02
    • 2020-11-17
    相关资源
    最近更新 更多