2012-09-20 38 views
1

我已經在我正在開發的rails網站上安裝了一個表單,並且我配置了jquery文件上傳插件。上傳表單工作正常。可以選擇多個文件,並且所有ajax上傳功能都可以正常工作。如何訪問一個數組/對象包含jQuery文件上傳插件中上傳的文件列表?

我遇到的問題是我需要爲用戶提供一種方法來「卸載」他們選擇上傳的文件。我有插件設置的方式允許用戶選擇或拖放文件,當文件被添加到他們被添加到暫存區域的表單中時(見下文)。我需要做的是允許用戶「unstage」或從窗體中刪除文件。

基本上我需要一種訪問和刪除jquery文件上傳表單中引用的文件的方式。

我正在使用基本的jquery文件上傳插件,沒有jQuery文件上傳附帶的所有可選腳本。這裏是一個鏈接到jQuery的文件上傳回購:https://github.com/blueimp/jQuery-File-Upload

screenshot http://f.cl.ly/items/3Q3o3m292h272p3f450s/Screen-Shot-2012-09-20-at-11.08.06-AM2.png

這裏是配置jQuery的文件上傳插件(此代碼被包裝在一個文檔準備功能)的JavaScript:

// initalize and configure the jQuery File Uploader 
$('#fileupload').fileupload({ 
    uploadTable: $('.file-upload-list'), 
    downloadTable: $('#photo'), 
    dropZone: dropZone, 
    sequentialUploads: true, 
    autoUpload: false, 
    maxFileSize:10000000, 
    dataType: 'text', 

    ... some code removed 

    // when the user drags a file into the upload area 
    drop: function (e, data) { 
    $('.file-upload-table').show(); 
    $.each(data.files, function (index, file) { 
     $('.file-upload-list').append('<li>' + file.name + '<a href="" class="close cancel"></a></li>'); 
}); 
    autoResizeColorbox(); 
    }, 

    // when the user selects a file normally 
    change: function (e, data) { 
    $('.file-upload-table').show(); 
    $.each(data.files, function (index, file) { 
     $('.file-upload-list').append('<li>' + file.name + '<a href="" class="close cancel"></a></li>'); 
}); 
    autoResizeColorbox(); 
    }, 

    ... some code removed 
}); 

任何幫助,非常感謝。

+1

您正在使用哪種文件上傳插件?你能給它一個鏈接嗎? –

+0

是的,我使用的只是從https://github.com/blueimp/jQuery-File-Upload – Stratus3D

+1

jquery.fileupload.js文件我看到他們的演示頁面正在使用模板呈現文件,並有取消按鈕從列表中刪除文件。也許你可以試着去那樣。此外,還有一些ui版本有一個名爲.destroy的方法。它用於刪除單獨的文件(破壞不是用戶版本只會刪除整個文件上傳) –

回答

0

我面臨同樣的問題,並找到答案。如果提交回調返回false,則相應的文件將不會上傳。

相關問題