Squ*_*Cat 1 javascript jquery scope jquery-file-upload
我遇到了jQuery File Uploader(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);
});
Run Code Online (Sandbox Code Playgroud)
这就是我点击开始上传按钮后提交所有内容的方式:
$(dataList).each(function(){
this.submit();
});
// This works well - the uploads are being submitted and sent to the server.
Run Code Online (Sandbox Code Playgroud)
我已经做了大量的解决方案搜索,测试,试错,调试1.5天了.我无法绕过这个.
我究竟做错了什么?
请注意:如果我data.submit()在add事件回调中执行了正确的操作,那么data.context在progress事件触发时会正确填充,但我不再需要手动启动整个上传队列.
Squ*_*Cat 11
这个问题的解决方案非常令人惊讶:
我对fileupload组件和插件的加载顺序是:
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
Run Code Online (Sandbox Code Playgroud)
最后一个(fileupload-ui.js)是陷阱.我认为我必须将它包含在我的上传器的实现中,但我没有.似乎我误解了它的用途.
我删除它的那一刻,我的脚本/实现开始工作,data.context现在正确填充.
| 归档时间: |
|
| 查看次数: |
3321 次 |
| 最近记录: |