1
嗨,大家好,我正在嘗試將最近流行的jQuery File Uploader與Rails 3捆綁在一起(雖然這與這個問題還沒有相關)。rails和動態javascript?
這個jQuery插件基本上允許多個文件上傳。我正在閱讀this page以瞭解如何在每次上傳時傳遞額外的POST數據。這是我遇到麻煩的地方。下面是該頁面提供作爲一個例子代碼:
$('.upload').fileUploadUI({
uploadTable: $('.upload_files'),
downloadTable: $('.download_files'),
buildUploadRow: function (files, index) {
var file = files[index];
return $(
'<tr>' +
'<td class="file_upload_start">' +
'<div class="ui-state-default ui-corner-all ui-state-hover" title="Start Upload">' +
'<span class="ui-icon ui-icon-circle-arrow-n">Start Upload<\/span>' +
'<\/div>' +
'<\/td>' +
'<td>' + file.name + '<\/td>' +
'<td class="file_upload_desc"><input type="text" title="File description"><\/td>' +
'<td class="file_upload_progress"><div><\/div><\/td>' +
'<td class="file_upload_cancel">' +
'<div class="ui-state-default ui-corner-all ui-state-hover" title="Cancel">' +
'<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
'<\/div>' +
'<\/td>' +
'<\/tr>'
);
},
// ...
我需要更換的部分是在file_upload_desc
輸入文本框。取而代之的是,我需要包括與構建的下拉控制:
f.collection_select :category_id, Category.all, :id, :name
這工作在靜態視圖,但我需要這個文件選擇上傳每次加。
我的困惑在於何處以及如何管理靜態視圖的動態下拉(動態,因爲它取決於瞭解哪些類別存在)的傳遞。
難道有事情做與創建一些視圖部分,然後做一些事情,如:
$.get("/partial", function(data) {
// blah blah
});
的問題是,每個插件的documentation,該buildUploadRow
必須返回HTML,所以我就一定得返回的數據並將其連接到返回結果,或其他。
一種可能性是靜態視圖,每當我需要動態地添加它當上載標記,clone()
它,一邊回憶擺脫了原來以避免干擾它的寫了這一點,一次,然後與張貼的數據。
任何幫助表示讚賞!
謝謝潘我真的很感謝迴應。我真的想用3號選項來做,但這是我感到困惑的地方。我會打電話給什麼檔案?謝謝! – 2011-02-07 02:37:07