也许我只是因为时间紧迫而迷惑自己,但是如果不重新加载页面本身我将如何重用此功能呢?
$(function() {
var uploadqueue = $("#uploader").pluploadQueue({
// General settings
runtimes : 'html4,silverlight',
url : 'upload_file.json?hdfs_url=<%=@file_name%>&authenticity_token=<%= form_authenticity_token %>',
max_file_size : '100000000000mb',
//chunk_size : '1mb',
unique_names : true,
multipart: false,
multiple_queues: true,
//multipart_params: {
//"authenticity_token" : '<%= form_authenticity_token %>'
//},
// Flash settings
flash_swf_url : 'javascripts/plupload/plupload.flash.swf',
// Silverlight settings
silverlight_xap_url : 'javascripts/plupload/plupload.silverlight.xap',
init : {
Refresh: function(up) {
// Called when upload shim is moved
$(".plupload_header_title").text("Upload files to HDFS");
$(".plupload_header_text").text("Files will go in: <%=@file_name%>");
},
StateChanged: function(up) {
// Called when upload shim is moved
$.get("file_tree?dir=<%=@file_name%>", function(data){
//alert("<%=@rel_link%>")
//alert("Command = ul[name*='<%=@rel_link%>']")
//alert("Data Loaded: " + $("ul[name*='<%=@rel_link%>']").html());
$("ul[name*='<%=@rel_link%>']").html($(data).children());
});
}
}
});
答案 0 :(得分:2)
只需将其定义为单独的功能。
function someFunction(){
// do your stuff
}
$(function(){
someFunction();
});
然后你可以在其他地方调用该函数。
注意,从技术上讲,document.ready中不需要函数包装器,但我发现在这种情况下它更容易理解。
答案 1 :(得分:2)
$(function(){
var uploadqueue = upload();
});
function upload()
{
return $("#uploader").pluploadQueue({...});
}
然后你可以在任何你喜欢的地方打电话给upload()
,在这之前确保文件准备就绪。