繁体   English   中英

获取错误Dropzone已经附加了角度指令

[英]Getting error Dropzone already attached with angular Directives

我正在使用以下代码放置区域,但我收到错误,我试图调试它,但我无法解决此操作PLZ指南

http://jsfiddle.net/anam123/rL6Bh/

 -------------------> "Error: Dropzone already attached.

  throw new Error("Dropzone already attached.");" 

码::

https://gist.github.com/compact/8118670

snippts:

 /**
 * An AngularJS directive for Dropzone.js, http://www.dropzonejs.com/
 * 
 * Usage:
 * 
 * <div ng-app="app" ng-controller="SomeCtrl">
 *   <button dropzone="dropzoneConfig">
 *     Drag and drop files here or click to upload
 *   </button>
 * </div>
 */

angular.module('dropzone', []).directive('dropzone', function () {
  return function (scope, element, attrs) {
    var config, dropzone;

    config = scope[attrs.dropzone];

    // create a Dropzone for the element with the given options
    dropzone = new Dropzone(element[0], config.options);

    // bind the given event handlers
    _.each(config.eventHandlers, function (handler, event) {
      dropzone.on(event, handler);
    });
  };
});

angular.module('app', ['dropzone']);

angular.module('app').controller('SomeCtrl', function ($scope) {
  $scope.dropzoneConfig = {
    'options': { // passed into the Dropzone constructor
      'url': 'upload.php'
    },
    'eventHandlers': {
      'sending': function (file, xhr, formData) {
      },
      'success': function (file, response) {
      }
    }
  };
});

通过使用以下代码设置解决了问题。

所以你可以:

  1. 像这样全局关闭autoDiscover: Dropzone.autoDiscover = false; , 要么
  2. 关闭特定元素的autoDiscover,如下所示: Dropzone.options.myAwesomeDropzone = false;

参考:
关于dropzone的常见问题

Dropzone.autoDiscover = false;
$('#bannerupload').dropzone({
    url: "/upload",
    maxFilesize: 100,
    paramName: "file",
    maxThumbnailFilesize: 5,
    init: function() {      
      this.on('success', function(file, json) {       
        jQuery("input#mediaid").val(json);
      });
    }
  });

没有什么对我有用所以我去了dropzone.js文件并更改了引发错误的行(我认为在许多版本中它在第426行):

if (this.element.dropzone) {
    throw new Error("Dropzone already attached.");
  }

所以我更换

throw new Error("Dropzone already attached.");

return this.element.dropzone;

它正在发挥作用

我遇到了同样的问题“Dropzone已经附加”,因为我们在脚本中启用了myDropzone对象并尝试再次启用。

例如

if ($('#upl').attr('class')) {

var myDropzone = new Dropzone("#upl", {init: function () {

并再次尝试启用它

 if (jQuery('#password').attr('save_profile')) {
  var myDropzone = new Dropzone("#upl", {init: function () {

与另一个行动。

请检查您的代码。

将您的create dropzone代码放在try / catch块中

try{
 $('.dropzone').dropzone({
    url: '/upload'
  });
}
catch(error){
    console.log("Catching " + error);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM