0

我需要有多个与fineuploader 实例相关的事件,但我不知道如何去做。不能将它们添加到 Fineuploader 属性等中吗?那么完整的事件不是称为onComplete吗?有没有存在的例子?另外,我对右括号的数量等感到困惑。当我最初剪切并粘贴这段代码时,有一个额外的 )}; 坐在外面。我删除了它,但我不确定这对于实际代码是否很酷。任何帮助表示赞赏,因为我已经玩了几个小时了。在此代码之外设置了一些变量。

$(document).ready(function () {

    var controlType = '@Model.ControlType';
    var surveyItemResultId = @Model.Results[0].SurveyItemResultId;
    var itemId = @Model.SurveyItemId;
    var instance = @Model.Results[0].SurveyInstanceID;
    var loopingCounter = 0; 

    var fineuploader = $('#files-upload').fineUploader({            
        request:
        {
            endpoint: '@Url.Action("UploadFile", "Survey")',
            customHeaders: { Accept: 'application/json' },
            params: {
                surveyInstanceId: (function () { return instance; }),
                surveyItemResultId: (function () { return surveyItemResultId; }),
                itemId: (function () { return itemId; }),
                loopingIndex: (function () { return loopingCounter++; })
            }             
        },
        validation: {
                acceptFiles: ['image/*','application/pdf','text/csv'] , 
                allowedExtensions: ['jpeg', 'jpg', 'gif', 'png', 'csv', 'pdf'],
                sizeLimit: 1024*1024*1 // 1MB
            },
       multiple: true,
       text: {
                uploadButton: '<i class="icon-plus icon-white"></i>Select your upload file(s)'
            }           
    })                   

      .on('complete', function(event, id, fileName, responseJSON) {
            alert("Success: " + responseJSON.success);

            uploadedFileCounter++;
            if (filesToUpload == uploadedFileCounter)
            {
                alert("DONE UPLOADING!");
            }           

    }).on('submitted', function(event, id, filename) {
            filesToUpload++;
            alert("submitted: " + filesToUpload);
        }
    });
});                                    
4

1 回答 1

0

您的代码充满了语法和其他错误。首先,您正在引用未在代码中任何地方定义filesToUploaduploadedFileCounter变量。其次,您的代码中有一个额外的右括号。

您的代码也存在一些格式问题。首先,您的代码缩进不一致。其次,您正在混合放置大括号。

这是您的原始代码和我的调整:

$(document).ready(function () {

    var controlType = '@Model.ControlType',
        surveyItemResultId = @Model.Results[0].SurveyItemResultId,
        itemId = @Model.SurveyItemId,
        instance = @Model.Results[0].SurveyInstanceID,
        loopingCounter = 0,
        filesToUpload = 0,
        uploadedFileCounter = 0;


    var fineuploader = $('#files-upload').fineUploader({
        request: {
            endpoint: '@Url.Action("UploadFile", "Survey")',
            customHeaders: { Accept: 'application/json' },
            params: {
                surveyInstanceId: (function () { return instance; }),
                surveyItemResultId: (function () { return surveyItemResultId; }),
                itemId: (function () { return itemId; }),
                loopingIndex: (function () { return loopingCounter++; })
            }
        },
        validation: {
            acceptFiles: ['image/*','application/pdf','text/csv'] ,
            allowedExtensions: ['jpeg', 'jpg', 'gif', 'png', 'csv', 'pdf'],
            sizeLimit: 1024*1024*1 // 1MB
        },
        multiple: true,
        text: {
            uploadButton: '<i class="icon-plus icon-white"></i>Select your upload file(s)'
        }
    })

        .on('complete', function(event, id, fileName, responseJSON) {
            alert("Success: " + responseJSON.success);

            uploadedFileCounter++;
            if (filesToUpload == uploadedFileCounter) {
                alert("DONE UPLOADING!");
            }

        }).on('submitted', function(event, id, filename) {
            filesToUpload++;
            alert("submitted: " + filesToUpload);
        });
});                                    
于 2013-08-27T18:54:47.043 回答