【问题标题】:Dropzone - Replace filename with link after upload is complete?Dropzone - 上传完成后用链接替换文件名?
【发布时间】:2017-03-14 19:09:54
【问题描述】:

我已经集成了 dropzone,它在上传文件等方面工作正常。我想做的是在上传成功后隐藏进度条,并自动将文件名替换为实际上传文件的链接。这将在每个文件完成上传时自动发生...

查看文档,我知道我应该使用

            this.on("success", function(file, response) {
                if (response.success == 'true') {
                  // hide progress bar '.dz-progress'
                  // replace .data-dz-name with url from response
                }
            });

但是,我无法弄清楚如何访问该特定 html 元素以替换/隐藏等。

编辑:我能够使用原始 dropzone.css 中的 css 类来隐藏/转换进度条。现在只需要找到一种方法将文件名替换为“a”标签。

【问题讨论】:

    标签: dropzone.js


    【解决方案1】:

    适用于 Dropzone 5.x 及以上

    更新缩略图的正确方法是修改成功回调中的Preview Template如下:

    this.on("success", function(file, response) {
        // modify the preview template
        file.previewTemplate.appendChild(document.createTextNode(response.filePath));
    });
    

    Reference tutorial 用于 Dropzone 以及服务器端处理

    【讨论】:

      【解决方案2】:
      $('.dz-progress').hide();
      

      $(".dz-progress").remove();
      

      并替换.data-dz-name

      $('.data-dz-name').html(url from response);
      

      【讨论】:

      • 这将设置“.data-dz-name”的所有个实例,而不仅仅是那个特定的“文件”实例。如果我同时删除 30 个文件,那么我希望每个文件都使用相应的 url 进行更新...
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      • 2015-12-22
      • 2020-07-15
      • 2016-02-18
      • 1970-01-01
      相关资源
      最近更新 更多