我正在构建一个 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 吗?或者简单地说,保留现有的那个?
最佳答案
所以,这是我找到的解决方法...
我没有使用回调,而是对 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));
});
}
关于angularjs - DropzoneJs 成功和错误回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28697794/