我试图让我的用户一次上传多张图片.现在一切都正常工作了,我唯一的问题是我没有在firebase firestore文档中获得作为数组的下载URL.

我正在使用arrayUnion()函数将所有内容合并到一个数组中,但它给了我这个错误."Unhandled Rejection (ReferenceError): arrayUnion is not defined"

我做错了什么?

这是我的代码:

firebase
      .firestore()
      .collection("Properties")
      .add({
        propname: propName,
        price: price,
        bedrooms: bedroom,
        bathroom: bathroom,
        exclusive: exclusive,
        area: area,
        type: type,
        category: category,
        features: features,
        services: services,
        summary: summary,
        // imageUrls: urls,
        location: location,
        salesAgentID: salesAgent,
        date: getCurrentDate(),
      })
      .then(result => {
        const promises = [];
        Promise.all(
          selectedImages.map(image => {
            const storageRef = storage.ref(
              `propertyImages/${result.id}/${image.name}`
            );
            storageRef.put(image).then(urls => {
              storageRef.getDownloadURL().then(downloadUrls => {
                console.log(downloadUrls);
                firebase
                  .firestore()
                  .collection("Properties")
                  .doc(result.id)
                  .update({
                    propertyID: result.id,
                    images: arrayUnion(downloadUrls),//here is my problem
                  })
                  .then(res => {
                    //handleUploadChange();
                    alert("Property Added Successfully");
                    window.location.reload();
                  });
              });
            });
          })
        );
      });
  

推荐答案

我通过使用Firebase文档(documentation link)中提到的这行代码firebase.firestore.FieldValue.arrayUnion(downloadUrls)解决了这个问题,因为他们升级了Firebase版本.

Reactjs相关问答推荐

单击按钮时在子元素中不显示任何内容-react

如何将图像(在代码中称为自己)定位在蓝色圈内的点上?我正在使用material UI和Reaction

useState导致对函数的无休止调用

根据处于react 状态的数组的名称键,将新对象添加到嵌套的对象数组中

.populate() 方法在 mongodb 中不起作用

单击按钮不会切换组件(当按钮和组件位于两个单独的文件中时)

ReactJS 共享上下文

如何使用服务器中的数据自动填充表单字段?

预期无限重新渲染但没有发生

在添加了useplacesautocomplete后,在构建React/Next.js项目时,NPM抛出类型期望的错误

BrowserRouter改变了URL但没有链接到页面

redux 工具包使用中间件构建器函数时,必须返回一个中间件数组

React - 使用 useEffect 还是直接在 onChange 方法中更改值对性能最好?

我应该如何将字符串作为props 传递给 React 组件?

在 React JS 中编辑表格数据

响应式媒体 React Tailwind

如何从 React Redux store 中删除特定项目?

如何在props 更改时运行自定义挂钩?

为什么我在此代码段中看不到 useEffect for count = 1?

React Hooks 表单在日志(log)中显示未定义的用户名