首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >data.context在jQuery文件Uploader的文件进程事件上为空

data.context在jQuery文件Uploader的文件进程事件上为空
EN

Stack Overflow用户
提问于 2013-10-07 14:55:11
回答 1查看 3.6K关注 0票数 1

我正在经历与jQuery文件Uploader (blueimp)有关的问题

我的实现是完全定制的。我使用图像预览和验证。

我的问题是,即使我在fileuploadadd事件中定义了fileuploadadd,但当fileuploadprogress被触发时,它就会变成空的。

代码语言:javascript
运行
复制
$('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);

});

点击“开始上传”按钮,我就是这样提交所有内容的:

代码语言:javascript
运行
复制
$(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将被正确填充,但是我不再有手动启动整个上传队列的选项。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-07 16:39:34

这个问题的解决方案非常令人惊讶:

我对fileupload组件和插件的加载顺序是:

代码语言:javascript
运行
复制
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现在得到了正确的填充。

票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19228063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档