data.context 在 jQuery File Uploader 的文件上传进度事件上为空
data.context is empty on fileuploadprogress event of jQuery File Uploader
我在使用jQuery文件上传器(blueimp)时遇到问题:
我的实现是完全定制的。我使用图像预览和验证。
我的问题是,即使我在fileuploadadd
事件中定义 data.context,当触发fileuploadprogress
时,它也是空的。
$('fileinput-element').fileupload({
url: '/__module/uploadModule/receive',
type: 'post',
acceptFileTypes: acceptedFileRegEx,
dataType: 'json',
'dropZone': $(dropZone),
paramName: 'files',
autoUpload: false,
}).on('fileuploadadd', function (e, data) {
$.each(data.files, function (index, file) {
// NOTE: This function call returns a clone of an element that i use as template for upload list items. Works fine.
var component=uploadModule.getDynamicComponent('listItemContainer');
// Filling the template (code omitted due to better readabilty)
// Appending the component to my #uploadList and assigning that to data.context
data.context = component.appendTo('#uploadList');
});
// For manual submittion later on, i fill an array with the data objects from each event call
dataList.push(data);
}).on('fileuploadprocessalways', function(e,data){
var index = data.index,
file = data.files[index],
node = $(data.context.children()[index]);
// Further code ommitted due to readability. Here i apply file.preview and (potential) file.error to my list item that is now stored in the variable node. This works fine. My list renders perfectly well.
}).on('fileuploadprogress', function(e, data){
// PROBLEM: data.context is EMPTY ! Why???
console.log(data.context);
});
这就是我在单击开始上传按钮时提交所有内容的方式:
$(dataList).each(function(){
this.submit();
});
// This works well - the uploads are being submitted and sent to the server.
我已经做了广泛的解决方案搜索,测试,试错,调试了1.5天。我只是无法理解这一点。
我做错了什么?
请注意:如果我在 add
事件回调中执行data.submit()
,那么当进度事件触发时data.context
会正确填充,但我不再可以选择手动启动整个上传队列。
这个问题的解决方案非常令人惊讶:
我对文件上传组件和插件的加载顺序是:
jquery
jquery-ui (for the widget
load-image.js
iframe-transport.js
fileupload.js
fileupload-process.js
fileupload-image.js
fileupload-validate.js
fileupload-ui.js
最后一个(fileupload-ui.js)是陷阱。我以为我必须将其包含在上传器的实现中,但我没有。看来我误解了它的用途。
我删除它的那一刻,我的脚本/实现开始工作,data.context
现在可以正确填充。
相关文章:
- 如何在elfinder插件(一个文件管理器插件)上获得上传前事件
- 如何使用Node.js在JavaScript模块文件之间使用事件处理程序
- 通过将文件上载到ASHX处理程序来实现SSE(服务器发送的事件)
- 在javascript中导入xlsx文件时,如何手动强制javascript事件
- Dropzone最大文件大小超过事件
- 选择同一文件时未触发HTML输入文件选择事件
- 如何在 iPhone 上打开启用了 CSS 事件的 HTML 文件
- 如何在jQuery中处理输入类型=文件的onchange事件
- XHTML文件头部分中的事件驱动函数
- 触发AngularJS中的输入文件点击事件
- 如何调用另一个js文件中的函数或触发一个自定义事件,该事件将参数作为Jquery中的数据对象传递
- 根据文件类型取消绑定和重新绑定click事件处理程序
- 如何从加载的JSON文件构建外部事件列表
- 如何在jquery/JavaScript中打开浏览文件对话框时执行取消事件
- 从驱动器打开文件时未调用Onfileloaded事件
- JQuery多文件事件未激发
- 如何查找jquery或javascript事件从哪个文件发生
- 如何在javascript中从ondrop事件中获取文件URL
- 如何在动态插入的html文件中使用onload事件
- 为什么在文件输入上触发点击事件也会在表单上触发提交事件