在dropzone .js的预览模板中为每个图像添加图像ID [英] Adding image id to each image in preview template in dropzone .js
本文介绍了在dropzone .js的预览模板中为每个图像添加图像ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想为每个使用dropzone.js上传的图片添加图片ID。
当前的预览模板就是这样。
I just want to add image id to each image that are uploaded using dropzone.js currently preview template is like this
<div class="dz-preview dz-image-preview" id="1">
<div class="dz-details">
<div class="dz-filename"><span data-dz-name="">car-menu03.jpg</span></div>
<div class="dz-size" data-dz-size=""><strong>85.9</strong> KiB</div>
<img data-dz-thumbnail="" alt="car-menu03.jpg" src="http://server1/akhil/workspace/XENSALE/assets/uploads/images/cars/2/car-menu03.jpg">
</div>
<div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress=""></span></div>
<div class="dz-success-mark"><span>✔</span></div>
<div class="dz-error-mark"><span>✘</span></div>
<div class="dz-error-message"><span data-dz-errormessage=""></span></div>
<a class="dz-remove" href="javascript:undefined;" data-dz-remove="">Remove</a>
</div>
推荐答案
此代码从服务器获取所有图像并初始化dropzone容器。
我希望这可以帮助你
This code get all images from the server and initialize the dropzone container. I hope this help you
// Initialize dropzone
init: function() {
thisDropzone = this;
// Call server to get all images in JSON format {id, filename, imagesize}
$.get("get-all-images", function(data) {
$.each(data.data, function(key,value){
var mockFile = { name: value.filename, size: value.imagesize };
thisDropzone.options.addedfile.call(thisDropzone, mockFile);
thisDropzone.options.thumbnail.call(thisDropzone, mockFile, value.file);
// On the created element added the id property
$(mockFile.previewElement).prop('id', value.id);
});
});
}
这篇关于在dropzone .js的预览模板中为每个图像添加图像ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文