DropzoneJs 成功和错误回调

Nun*_*iro 3 callback angularjs dropzone.js

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

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

没有回调成功没有回调错误

var myDropzone = $("#storageDropzone").dropzone({
    url: firstUrl,        
}); 
Run Code Online (Sandbox Code Playgroud)


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

回调成功有回调错误

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");
    }
}); 
Run Code Online (Sandbox Code Playgroud)

那么,我可以更改回调中的 previewTemplate 吗?或者简单地说,保持存在的那个?

Nun*_*iro 7

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

我没有使用回调,而是对 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));
        });
  }
Run Code Online (Sandbox Code Playgroud)