如何在Dropzone.js和jsGrid中仅上传和显示一个文件?

问题描述 投票:0回答:1

我有一个Dropzone控件和一个jsGrid控件。拖到Dropzone的文件显示在jsGrid中。我只希望上传一个文件,之后,就没有选择上传文件了。现在可以通过以下方法解决。

每次在jsGrid上触发更改事件,否。计数jsGrid中的行数。如果计数为0,则启用Dropzone;如果计数为1,则禁用Dropzone。我似乎找不到用于计数no的代码。 jsGrid中的行数。请帮助我提供代码。

也请让我知道是否还有另一种解决方法。

这是我的表单的屏幕截图:

enter image description here

提前感谢。

javascript jquery jquery-file-upload dropzone jsgrid
1个回答
0
投票

我已经通过使用CSS禁用Dropzone控件解决了该问题。

.maxFilesReached {
        pointer-events: none;
        cursor: default;
        background-color: #ffd9d8
}

此CSS类在成功后被添加到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');
                    }
                });
            }

类似地,在jsGrid的deleteItem事件发生时,CSS类也被删除。

deleteItem: function (item) {
                    return $.ajax({
                        type: "POST",
                        url: "/Downloads/DDownloadItem/" + item.Id,
                        dataType: "json"
                    }).done(function () {
                        // enabling Dropzone control
                        $("#dropzoneForm").removeClass('maxFilesReached');
                    });
                }

我还使用了Dropzone的maxFiles属性来阻止多个上传。

P.S。 jsGrid有点混乱。

© www.soinside.com 2019 - 2024. All rights reserved.