簡體   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