gpt4 book ai didi

javascript - dropzone js 链接删除 url 与删除按钮

转载 作者:数据小太阳 更新时间:2023-10-29 04:33:36 27 4
gpt4 key购买 nike

在 Dropzonejs 中,我正在创建删除按钮,然后将其附加到缩略图,如何使用 addRemoveLinks:true 将我从服务器直接获取的 url 链接到删除按钮,

//Write function if you need to add some event after files added
myDropzone.on("addedfile", function(file) {
console.log('Files Added using ---------->'+$attrs.apiCall);
var _this=this;
/* Maybe display some more file information on your page */
var removeButton = Dropzone.createElement("<button data-dz-remove>-Remove file</button>");
removeButton.addEventListener("click", function(e) {
e.preventDefault();
e.stopPropagation();
_this.removeFile(file);
});
file.previewElement.appendChild(removeButton);
});

最佳答案

您可以添加删除链接..在添加文件事件中,您可以在服务器响应中获取URL并在删除链接中设置它。

 myDropzone.on("addedfile", function (file) {
var _this = this;

/* Maybe display some more file information on your page */
var removeButton = Dropzone.createElement("<button data-dz-remove " +
"class='del_thumbnail btn btn-default'><span class='glyphicon glyphicon-trash'></span></button>");

removeButton.addEventListener("click", function (e) {
e.preventDefault();
e.stopPropagation();
var server_file = $(file.previewTemplate).children('.server_file').text();
// Do a post request and pass this path and use server-side language to delete the file
// $.post(server_file,{'X-CSRFToken': $cookies.csrftoken}, 'json');
$http({
method: 'POSt',
url: server_file,
headers: {
'X-CSRFToken': $cookies.csrftoken
}
});
_this.removeFile(file);
});
file.previewElement.appendChild(removeButton);
});

关于javascript - dropzone js 链接删除 url 与删除按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24238193/

27 4 0
文章推荐: javascript - 无穷大是javascript中的某个数字吗?
文章推荐: c# - List 上的 Parallel.ForEach 线程安全