我正在尝试在Dropzone.js中为每个上传的文件添加id属性,以便稍后可以对其进行排序。
这是我的代码:
但我似乎找不到把它添加到dz-preview元素的方法。
HTML结构如下:
感谢您的帮助 :)
这是我的代码:
Dropzone.options.pictureDropzone = {
paramName: "file",
addRemoveLinks: true,
init: function() {
this.on("success", function(file, response) {
file.serverId = response.id;
$(file.previewTemplate).find('.dz-preview').attr('id', "document-" + file.serverId);
});
}
};
这行代码
$(file.previewTemplate).find('.dz-preview').attr('id', "document-" + file.serverId);
应该添加id,但是没有任何作用。也尝试使用prop()。
如果我选择不同的元素,它可以正常工作。例如,对于.dz-details,这样可以工作。
$(file.previewTemplate).find('.dz-details').attr('id', "document-" + file.serverId);
但我似乎找不到把它添加到dz-preview元素的方法。
HTML结构如下:
<div class="dz-preview dz-processing dz-image-preview dz-success">
<div class="dz-details"> ... </div>
<div class="dz-progress"> ... </div>
<div class="dz-success-mark"> ... </div>
</div>
感谢您的帮助 :)
init
函数的相关票证:https://dev59.com/qI3da4cB1Zd3GeqPzGX6#31627155 然后向this.addCustomFile
函数传入第四个参数id
,在函数中添加file.previewElement.id = id;
,接着在通过服务器代码(PHP等)获取的图像中,在for
循环中添加id。 - Ryan