问题描述
有关一些快速背景,uploadStoredFiles()是在FineUploader插件用于附加文件数据异步发送到服务器的路径的方法。我还使用AngularJS我的应用程序。我的问题其实很相似,在这里找到一个...
For some quick background, uploadStoredFiles() is a method used in the FineUploader plugin to asynchronously send attached file data to a server path. I'm also using AngularJS for my application. My question is actually very similar to the one found here...
jQuery:等待函数来完成,继续处理?
...最大的区别是,我没有进入回调函数本身。另外,我的脚本运行FineUploader作为一个更大的形式,其中的附件是可选的一部分,因此,使用'完成'回调将帮助不大无论是FineUploader。
... the big difference is that I don't have access to the callback function itself. Also, my script is running FineUploader as part of a larger form where attachments are optional, so using a FineUploader 'completed' callback won't help much either.
下面是一个code样品。基本上,如果没有附件那么页面重新载入。如果有附件,它们应该被上载,然后在页面重新载入。
Here's a code sample. Basically, if there are no attachments then the page should reload. If there are attachments, they should be uploaded, and THEN the page should reload.
if(hasAttachments)
{
myuploader.uploadStoredFiles();
}
//AngularJS call to refresh page
$route.reload();
在大多数情况下,页面刷新本身和文件将从其列表失踪,直到我后来做了一个额外的刷新。我可以硬code等待时间,但一些有关这似乎效率不高和邪恶的。
Most of the time, the page refreshes itself and the file is missing from its list until I do an additional refresh later on. I could hard code a wait time, but something about that seems inefficient and evil.
任何建议或解决方案将受到欢迎。我特别喜欢的角度十岁上下的解决方案,但我会采取什么我可以得到的。
Any suggestions or solutions would be welcome. I would especially love an Angular-ish solution, but I'll take what I can get.
推荐答案
我企图在总结我的意见成一个有凝聚力的回答:
My attempt at summarizing my comments into a cohesive answer:
精细上传器上运行code当某些事情发生,当一个文件被提交给上传者如事件(的onsubmit
),或在一个文件上传( 的onComplete
)。
Fine Uploader has events that run code when certain things happen such as when a file is submitted to the uploader (onSubmit
) or when a file has uploaded (onComplete
).
香草的JavaScript看起来像,
The vanilla JavaScript would look something like,
$(document).ready(function() {
$("#triggerUpload").click(function () {
$("#manual-fine-uploader").fineUploader('uploadStoredFiles');
});
function submitForm () {
if ($(this).fineUploader('getInProgress') == 0) {
var failedUploads = $(this).fineUploader('getUploads',
{ status: qq.status.UPLOAD_FAILED });
if (failedUploads.length == 0) {
// do any other form processing here
$("#uploader").submit();
}
}
};
// Instantiate a Fine Uploader instance:
$("#manual-fine-uploader").fineUploader({
autoUpload: false,
request: {
endpoint: "/uploads_bucket"
}
}).on("complete", function (event, id, name, response) {
submitForm.call(this);
}).on('statusChange', function (event, id, oldStatus, newStatus) {
if (newStatus === qq.status.CANCELLED) {
submitForm.call(this);
}
});
});
您可以使用这个Angluar 的例子作为起点,制作精细上传指令。
You can use this Angluar example as a starting point for making a Fine Uploader directive.
这篇关于需要FineUploader方法uploadStoredFiles来完成,然后再继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!