简体   繁体   English

如何重新初始化jQuery文件上传数据数组?

[英]How do I re-initialize jQuery file upload data array?

I'm using jQuery file upload in my web site for users to upload there Photos. 我在我的网站上使用jQuery文件上传 ,以便用户将照片上传到那里。 Following is my JS code calling file upload plugin, (Please have a look at code comments as well...) 以下是我的JS代码调用文件上传插件,(请同时查看代码注释...)

$('#fileupload').click(function(){  
$('#fileupload').fileupload({
        dataType: 'json',
        url: 'productpage/uploadphoto?design='+ globalVars.selectedDesignId,
        prependFiles: true,
        start: function(){
            $("#pp-photo-area").show();
        },
        done: function (e, data) {
            console.log(data); // Only gives me new file data
            loadPhotoStudio(data); //Data is sent to another function
        }           
    }); 
});

And each time a user uploads a file it get added to the data array with the old file data in it, which I dont want to happen. 每次用户上载文件时,它都会添加到其中包含旧文件数据的数据数组中,我不想发生这种情况。 I want it to replace the previous data array with the new one. 我希望它用新的替换以前的数据数组。 So that I can use this data in loadPhotoStudio() function. 这样我就可以在loadPhotoStudio()函数中使用此数据。

var loadPhotoStudio = function(data) {
  $('#test').click(function(){
        $.each(data.result.files, function (index, file) {
            console.log(file.name) //This gives me all files uploaded
        });
    });   
}

How do I refresh data array before each upload? 如何在每次上传之前刷新数据数组?

try to add this to the 'done' queue: 尝试将其添加到“完成”队列中:

reset_field($('#fileupload'));

Corresponding to this function 对应此功能

function reset_field (e) {
        e.wrap('<form>').parent('form').trigger('reset');
        e.unwrap();
}   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM