Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Javascript中重置FilePond输入_Javascript_Jquery_File Upload_Filepond - Fatal编程技术网

在Javascript中重置FilePond输入

在Javascript中重置FilePond输入,javascript,jquery,file-upload,filepond,Javascript,Jquery,File Upload,Filepond,我已经实现了在我的页面上传的Filepond。当用户选择一个文件时,我将该文件设置在html画布上进行编辑。但是,当用户想要上载另一个文件时,filepond input会保留上次上载的文件 我尝试了FilePond.destroy(inputElement)在FilePond:addfile事件中在画布上成功设置文件后 $('.upload-file').filepond(); $.fn.filepond.registerPlugin( FilePondPluginFileVali

我已经实现了在我的页面上传的Filepond。当用户选择一个文件时,我将该文件设置在html画布上进行编辑。但是,当用户想要上载另一个文件时,filepond input会保留上次上载的文件

我尝试了
FilePond.destroy(inputElement)
FilePond:addfile
事件中在画布上成功设置文件后

 $('.upload-file').filepond();

$.fn.filepond.registerPlugin(
    FilePondPluginFileValidateType,
    FilePondPluginFileValidateSize,
    FilePondPluginImageResize,
    FilePondPluginImageExifOrientation,
    FilePondPluginImagePreview,
    FilePondPluginImageTransform,
    FilePondPluginImageCrop,
    FilePondPluginImageValidateSize,
);


     FilePond.setOptions({
      labelIdle: 'Drag & Drop your file or <span class="filepond--label- 
       action"> Browse </span>',
    maxFiles: 1,
    allowDrop: true,
    allowMultiple: false,
    dropOnPage: true, //for page to work, element has to be false https://github.com/pqina/filepond/issues/113
    dropOnElement: false,
    labelTapToCancel: '', //we dont want to allow cancel
    labelTapToUndo: '',
    maxFileSize: intFileSizeInMB,
    allowReplace: true,
    allowRevert: false,
    instantUpload: false 
});



const pond = document.querySelector('.filepond--root');

pond.addEventListener('FilePond:addfile', e => {

    console.log('File added', e.detail);

    if (e.detail) {
        if (e.detail.file && e.detail.file.file.name) {
            SetFileOnCanvas(e.detail.file.file, e.detail.file.file.name);

            const inputElement = document.querySelector('input[type="file"]');
            FilePond.destroy(inputElement); 
        }
    }
});



pond.addEventListener('FilePond:processfile', e => {
    console.log('Process File COMPLETE', e.detail);
});
$('.upload file').filepond();
$.fn.filepond.registerPlugin(
FilePonPluginFileValidateType,
FilePonPluginFileValidateSize,
FilePonPluginImageResize,
FilePondPluginImageExiforOrientation,
FilePonPluginImagePreview,
FilePonPluginImageTransform,
FilePonPluginImageCrop,
FilePonPluginImageValidateSize,
);
FilePond.setOptions({
labelIdle:'拖放文件或浏览',
maxFiles:1,
allowDrop:是的,
allowMultiple:false,
dropOnPage:true,//要使页面正常工作,元素必须为falsehttps://github.com/pqina/filepond/issues/113
DroponeElement:错,
labelTapToCancel:“”,//我们不希望允许取消
labelTapToUndo:,
maxFileSize:intFileSizeInMB,
地点:对,
allowRevert:错,
instantUpload:false
});
const pond=document.querySelector('.filepond--root');
addEventListener('FilePond:addfile',e=>{
console.log('File added',e.detail);
如果(如细节){
if(e.detail.file&&e.detail.file.file.name){
SetFileOnCanvas(e.detail.file.file,e.detail.file.file.name);
const inputElement=document.querySelector('input[type=“file”]”);
文件池。销毁(inputElement);
}
}
});
addEventListener('FilePond:processfile',e=>{
console.log('processfile COMPLETE',e.detail);
});
上传文件并设置为画布后,应清除文件上传输入,并准备再次上传。

上传文件后“完成功能”

您可以这样做(简单示例):

if(filePond.getFiles().length!=0){
对于(var i=0;i工作溶液

var pond_ids = [];

if (pond.getFiles().length != 0) {  // "pond" is an object, created by FilePond.create 
    pond.getFiles().forEach(function(file) {
        pond_ids.push(file.id);
    });
}

pond.removeFiles(pond_ids);

您不能调用
removeFile
?在上载完成时删除该项吗?我尝试在FilePond:addfile事件中执行“pond.removeFile”,但那里没有pond对象实例。
$('.upload file').FilePond('removeFile');
如果您使用jQuery适配器,类似的操作应该可以使用。
var pond_ids = [];

if (pond.getFiles().length != 0) {  // "pond" is an object, created by FilePond.create 
    pond.getFiles().forEach(function(file) {
        pond_ids.push(file.id);
    });
}

pond.removeFiles(pond_ids);