【问题标题】:DropzoneJs success and error callbackDropzoneJs 成功和错误回调
【发布时间】:2015-02-24 14:02:09
【问题描述】:

我正在构建一个 AngularJs 应用程序,并且我正在使用 DropzoneJs 中的一个 dropzone。我需要使用成功和错误回调,因为我必须访问服务器响应。我有一个问题,如果我使用回调,previewTemplate 会发生变化......那么,我可以在回调中更改 previewTemplate 吗?

如果我不使用回调,这里是结果模板和代码:

var myDropzone = $("#storageDropzone").dropzone({
    url: firstUrl,        
}); 


如果我使用回调,“勾号”或“十字”不会出现:

var myDropzone = $("#storageDropzone").dropzone({
    url: firstUrl,
    error: function (file, response) {
        console.log("Erro");
        console.log(response);
    },
    success: function (file, response) {
        console.log("Sucesso");
        console.log(response);
    },
    complete: function (file) {
        console.log("Complete");
    }
}); 

那么,我可以更改回调中的 previewTemplate 吗?或者简单地说,保留现有的?

【问题讨论】:

    标签: angularjs callback dropzone.js


    【解决方案1】:

    所以,这就是我找到的解决方法...

    我没有使用回调,而是对 init 函数进行了更改。虽然这个答案不能让我满意,但这是我目前能做的最好的了......如果有人能解释为什么它在 init 上工作但不能作为回调,请随时回答。

    这是解决方案:

    var myDropzone = $("#storageDropzone").dropzone({
        init: function () {
            this.on("processing", function (file) {
                $scope.$apply($scope.working = true);
                this.options.url = lastUrl;
                $scope.$apply($scope.processing = true);
            });
    
            this.on("success", function (file, response) {
                console.log("sucesso");
                var ficheiro = { nome: file.name, link: response[0] };
                $scope.$apply($scope.uploadedFiles.push(ficheiro));
            });
    
            this.on("error", function (file, error, xhr) {
                var ficheiro = { nome: file.name, status: xhr.status, statusText: xhr.statusText, erro: error.message };
                $scope.$apply($scope.errorFiles.push(ficheiro));
            });
      }
    

    【讨论】:

      【解决方案2】:

      我认为正在发生的事情是,由于您要覆盖默认的 DropZone“错误”和“成功”回调函数,因此不会在文件上传图块上创建“滴答”和“交叉”。不是模板变了,而是模板变了。您正在覆盖默认的 DropZone 错误和成功行为。要显示“tick”和“cross”,您需要将默认 DropZone 错误和成功回调函数中的代码复制到您的函数中,然后实现您需要的任何其他或更改的行为。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-07-25
        • 1970-01-01
        • 2013-07-01
        • 2023-03-24
        • 2017-08-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多