javascript – 在dropzone .js中的预览模板中为每个图像添加图像ID
作者:互联网
我只想为使用dropzone.js上传的每个图像添加图像ID
目前的预览模板是这样的
<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容器.
我希望这对你有帮助
// 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);
});
});
}
标签:html,javascript,jquery,dropzone-js 来源: https://codeday.me/bug/20190830/1769355.html