简体   繁体   English

Dropzone JS-不接收选项

[英]Dropzone js - not picking up options

My dropzone works fine but does not pickup the options. 我的Dropzone工作正常,但无法使用这些选项。

The init function is never called. 永远不会调用init函数。

<div class="row">
    <form method="post" id="uploadFiles" style="width:200px; height:100px; border:1px solid red;">
        {{ csrf_field() }}
    </form>
</div>

<script>

$(function() {

    Dropzone.autoDiscover = false;
    var myDropzone = new Dropzone("#uploadFiles", { url: "{{Request::url()}}", method:"post"});
    console.log(myDropzone);
    Dropzone.options.uploadfiles = {
  paramName: "file", // The name that will be used to transfer the file
  maxFilesize: 2, // MB
    init: function() {
      alert('init called');
  },
  accept: function(file, done) {
    if (file.name == "justinbieber.jpg") {
      done("Naha, you don't.");
    }
    else { alert('not accepted') }
  },

};

You are adding options to Dropzone which is a refrerence to the library, not the Dropzone object you just created ( myDropzone ). 您正在向Dropzone添加选项,这是对库的引用,而不是刚刚创建的Dropzone对象( myDropzone )。 Change your code to: 将您的代码更改为:

myDropzone.options = {
    ... // Your options here
};

This applies your options to the dropzone object you created. 这会将您的选项应用于您创建的dropzone对象。 When interacting with your dropzone programatically, you should always reference this myDropzone instance. 以编程方式与dropzone交互时,应始终引用此myDropzone实例。

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

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