如何在ant-d上传中添加PopConfirm以将removeFile添加为图像文件 [英] How to add PopConfirm for removeFile an image file in ant-d upload

查看:323
本文介绍了如何在ant-d上传中添加PopConfirm以将removeFile添加为图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ant-d Upload通过本地系统上传文件,然后单击文件预览图像上的删除图标删除了图像文件.我想添加一个弹出确认,因此我尝试将a添加确认为在onRemovefunction中保证但不起作用.它在浏览器中显示警报.

I'm using Ant-d Upload for uploading files through local system and on clicking on delete icon on preview image of file the image file is deleted.I want to add a pop confirm so I tried a to add confirm as a promise in onRemovefunction but it is not working.It is showing an alert in browser.

 onGalleryFileRemove = (file)=>{
 return new Promise((resolve, reject) => {
  confirm({
    title: 'are you sure to remove this file?',
      onOk: () => {
        resolve(true)
      },
  })
    const index = this.state.galleryFile.indexOf(file);
    const deletedGalleryFiles = this.state.deletedGalleryFiles;
    deletedGalleryFiles.push(this.state.galleryFile[index].uid);
    const newFileList = this.state.galleryFile.slice();
        newFileList.splice(index, 1);
            this.setState({
                galleryFile:newFileList,
                deletedGalleryFiles,
                previewVisible:false 
            })
    false    
    })
}
<Upload
    listType="picture-card"
    beforeUpload={this.beforeFileUpload}
    fileList={this.state.galleryFile}
    onPreview={this.handlePreview}
    onChange={this.handleGalleryFileChange}
    onRemove={this.onGalleryFileRemove}
>
  {this.state.galleryFile.length >= 6 ? null : uploadGalleryButton}
</Upload>
<Modal visible={this.state.previewVisible} footer={null} onCancel={this.handleCancel}>
  <img alt="previewImage" style={{ width: '100%' }} src={this.state.previewImage} />
</Modal>

推荐答案

幸运的是,我得到了一个解决方案.我知道有人可以在这个庞大的社区中为我提供帮助,我认为这可能对任何人都有用

Luckily, I got a solution for this.I know someone might help me in this huge community I thought it might be useful for anyone

 onGalleryFileRemove = (file)=>{
   const {confirm} = Modal
   return new Promise((resolve, reject) => {
    confirm({
      title: 'Are you sure you want to Delete ?',
      onOk: () => {
        resolve(true)
           <!---- onRemoveFunctionality here ---->
      },
      onCancel: () =>{
         reject(true)
      }
    })
   })
 }

这篇关于如何在ant-d上传中添加PopConfirm以将removeFile添加为图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆