[英]How to upload and display only one file in Dropzone.js and jsGrid?
I have a Dropzone
control and a jsGrid
control.我有一个Dropzone
控件和一个jsGrid
控件。 Files that are dragged to the Dropzone are displayed in jsGrid.拖到 Dropzone 的文件显示在 jsGrid 中。 I want only one file to be uploaded and after it, there should be no option to upload files.我只想上传一个文件,在它之后,应该没有上传文件的选项。 Now it can be solved by the following approach.现在可以通过以下方法解决。
Every time the change event is triggered on jsGrid, no.每次在 jsGrid 上触发 change 事件时,都不会。 of rows in jsGrid are counted.计算 jsGrid 中的行数。 Dropzone is enabled if the count is 0 and disabled if the count is 1. I can't seem to find the code for counting the no.如果计数为 0,则启用 Dropzone,如果计数为 1,则禁用 Dropzone。我似乎找不到计数编号的代码。 of rows in jsGrid. jsGrid 中的行数。 Kindly help me with the code.请帮我写代码。
Also, let me know if there's another way to solve it.另外,让我知道是否有其他方法可以解决它。
Here's the screenshot of my form:这是我的表单的屏幕截图:
Thanks in advance.提前致谢。
I have solved the issue by using CSS to disable the Dropzone control.我已经通过使用 CSS 禁用 Dropzone 控件解决了这个问题。
.maxFilesReached {
pointer-events: none;
cursor: default;
background-color: #ffd9d8
}
This CSS class is added to the jsGrid loadData
event upon success.此 CSS class 在成功时添加到 jsGrid loadData
事件。
loadData: function (filter) {
return $.ajax({
type: "POST",
url: "/Downloads/GetDownloadItems/" + DownloadId,
data: filter,
dataType: "json"
}).done(function (response) {
debugger;
if (response.length == 1) { // disabling Dropzone control
$("#dropzoneForm").addClass('maxFilesReached');
}
});
}
Similarly, the CSS class is removed upon the deleteItem
event of jsGrid.同样,CSS class 在 jsGrid 的deleteItem
事件时被删除。
deleteItem: function (item) {
return $.ajax({
type: "POST",
url: "/Downloads/DDownloadItem/" + item.Id,
dataType: "json"
}).done(function () {
// enabling Dropzone control
$("#dropzoneForm").removeClass('maxFilesReached');
});
}
I have also used the maxFiles
property of Dropzone to prevent more than one uploads.我还使用了 Dropzone 的maxFiles
属性来防止多次上传。
PS jsGrid is kind of messy. PS jsGrid 有点乱。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.