【发布时间】:2022-09-27 21:35:06
【问题描述】:
我在我的Spring MVC 应用程序中使用Dropzone 和jQuery 和Thymeleaf。
通过最少的配置,Dropzone 工作出色,只有一个小问题。我将autoProcessQueue 设置为false,以便在单击提交按钮之前不会处理队列。这意味着进度条(在单击提交按钮之前显示为 0 进度)会遮盖预览中的文件名。这可以在附图中看到。这三个文件名在进度条后面几乎可见,但它们非常暗淡。
我的 Dropzone 配置粘贴在下面:-
Dropzone.options.frmTarget = {
autoProcessQueue: false,
paramName: \'file\',
clickable: true,
maxFilesize: 20,
uploadMultiple: false,
parallelUploads: 10,
maxFiles: 20,
addRemoveLinks: true,
acceptedFiles: \'.png,.jpg,.pdf,.doc,.docx,.xls, .xlsx,.xml,.bmp,.msg,.txt\',
dictDefaultMessage: \'Drag files or click here to select\',
init: function () {
var myDropzone = this;
myDropzone.removeAllFiles();
myDropzone.on(\"complete\", function(file) {
myDropzone.removeFile(file);
});
myDropzone.on(\"queuecomplete\", function (file) {
$(\"#dropzone-info\").show().delay(3500).fadeOut();
});
$(\"#button\").click(function (e) {
e.preventDefault();
myDropzone.processQueue();
});
$(\"#button1\").click(function (e) {
e.preventDefault();
myDropzone.removeAllFiles();
});
}
}
这就是 Dropzone 添加到 HTML 页面的方式,它与表单中的其他元素结合使用 Thymeleaf 将模型数据绑定到表单:-
<form id=\"frmTarget\"
th:object=\"${metadataListWrapper}\"
class=\"dropzone\"
th:action=\"@{/content/upload/{app}(app=${metadataListWrapper.applicationName})}\"
method=\"post\">
<div th:if=\"${not #lists.isEmpty(metadataListWrapper.metadataDefinitionList)}\"
th:each=\"metadataHolder, iStat : ${metadataListWrapper.metadataDefinitionList}\">
<div th:if=\"${metadataHolder.includeInIngestionForm == true}\">
<input th:field=\"*{metadataDefinitionList[__${iStat.index}__].value}\" type=\"hidden\"/>
<span th:replace=\"fragments/non-value-hidden-fields :: non-value-hidden-fields\"></span>
</div>
</div>
<input th:field=\"*{applicationName}\" type=\"hidden\"/>
<input th:field=\"*{applicationDisplayName}\" type=\"hidden\"/>
</form>
我将非常感谢任何解决此问题的建议和想法。例如,是否可以将进度条向下移动,使其显示在文件名下方而不是文件名上方,或者在启动上传之前根本不显示进度条?或者进度条的不透明度可以降低到 50%?非常感谢。
标签: javascript html jquery spring-mvc dropzone.js