在jquery文件上传中调用默认的done函数



我正在使用Jquery文件上传插件来上传文件。

    jQuery('#UploadForm-form').fileupload({
'maxFileSize':20000000,
'acceptFileTypes':/(.|/)(csv)$/i,
'done':function(e,data)
       {
        // do something here
       // call defaultDone here        
       },
'url':'/manage/upload?parent_id=1',
'autoUpload':false,
'maxNumberOfFiles':1});

问题是,在上面的done函数中,我想做一些事情,然后调用插件提供的默认done函数。

我该怎么做?

您必须记住您的默认函数。希望您能从下面的代码中得到一些想法。

// Initialize your file upload object
jQuery('#UploadForm-form').fileupload({
    'maxFileSize' : 20000000,
    'acceptFileTypes' : /(.|/)(csv)$/i,
    // Don't override default done function here
    // You have to memoize default function from widget instance later.
    // Hence, I comment following line
    // 'done':function(e,data)
    // {
    // // do something here
    // // call defaultDone here
    // },
    'url' : '/manage/upload?parent_id=1',
    'autoUpload' : false,
    'maxNumberOfFiles' : 1
});
// Memoize and call the default done as follows.
var widgetInstance = $('#UploadForm-form').data('blueimp-fileupload') || $('#UploadForm-form').data('fileupload');
widgetInstance.options.defDoneFn = widgetInstance.options.done
widgetInstance.options.done = function myCustomFn() {
    // do something here
    widgetInstance.options.defDoneFn .apply(this, arguments);
};

注意:我已经针对http://blueimp.github.io/jQuery-File-Upload/basic.html.如果您使用不同版本的fileupload,可能会有一些更改,如数据密钥(.data(<data key>)

最新更新