【问题标题】:Populate dropzone.js with image from the database issue removing images使用数据库中的图像填充 dropzone.js 删除图像
【发布时间】:2015-04-12 20:37:37
【问题描述】:

我在调用数据库后尝试删除通过 dropzone.js 的文件时遇到问题。

当我导航到该页面并上传新图像,然后在不刷新页面的情况下将其删除时,一切都按预期工作。

以下是我目前的上传方式

 myDropzone.on("success", function (file, response) {
                    console.log(response);
                    file.serverId = response;
                });

这是执行 console.log(response); 后响应中的内容;

 Object { UniqueId="evgopvdjfs1w9sos3jt5"}

哪个是正确的。

现在,当我按 F5 并刷新页面时,我会使用以下 sn-p 填充 dropzone,这会返回我刚刚上传的图像。

$.getJSON("/Person/GetPreviews/").done(function (data) {
        if (data.Data != '') {

            $.each(data.Data, function (index, item) {

                var UniqueId = item.ImageName;

                var mockFile = {
                    name: item.ImageName,
                    serverId: UniqueId // This is what I need to delete the image
                };

                console.log(mockFile);

                // Call the default addedfile event handler
                myDropzone.emit("addedfile", mockFile);

                // And optionally show the thumbnail of the file:
                myDropzone.emit("thumbnail", mockFile, item.ImageUrl);

                myDropzone.files.push(mockFile);
             });
          }
  });

现在当我做 console.log(mockFile);如下所示,再次正确。

 Object { name="evgopvdjfs1w9sos3jt5", UniqueId="evgopvdjfs1w9sos3jt5"}

现在说到删除文件,这是我当前的删除功能

 removedfile: function (file) {
                console.log(file);

                $.ajax({
                    type: 'POST',
                    url: '@Url.Action("DeleteUploadedFile", "Person", new {userId= @Model.UserId})',
                    data: "id=" + file.serverId['UniqueId'],
                    dataType: 'html',
                });
                var ref;
                return (ref = file.previewElement) != null ? ref.parentNode.removeChild(file.previewElement) : void 0;
            },

现在,当我从数据库中按预填充图像上的删除文件时,它会在

上引发错误
data: "id=" + file.serverId['UniqueId'], 

说它不够精细,我个人看不出是怎么回事,因为两个 console.logs 都显示了 UniqueId,这让我想知道当我用图像预先填充 dropzone 时我是否遗漏了什么?

如您所见,我有一个 console.log(file);在删除功能中,点击时显示以下内容

 Object { name="evgopvdjfs1w9sos3jt5", UniqueId="evgopvdjfs1w9sos3jt5"}

任何人都可以看到有什么问题吗?

【问题讨论】:

    标签: javascript dropzone.js


    【解决方案1】:

    所以这个问题有点老了。我遇到了它,也找到了这个答案,这对我有帮助:

    http://www.stackoverflow.com/questions/24445724/add-existing-image-files-in-dropzone

    此特定问题已在此处得到解答,只是指出了 serverId 和 UniqueId 之间的混淆:

    https://github.com/enyo/dropzone/issues/844

    【讨论】:

      猜你喜欢
      • 2017-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-16
      • 1970-01-01
      • 2018-01-05
      • 2020-03-05
      相关资源
      最近更新 更多