向图像添加字段(输入)(adding fields (inputs) to images)

编程入门 行业动态 更新时间:2024-10-25 20:18:16
向图像添加字段(输入)(adding fields (inputs) to images)

即时通讯使用dropzone上传多个图像,并且工作正常,直到我想为每个图像插入品牌和网址。

我唯一的问题就是当我要从输入字段中获取值时,我从服务器获取来自fieds(品牌,网址)的未定义值的myt请求但是如果我使用静态文本它似乎没有问题。

这是我的代码:

$('#add').on('click',function(e){ e.preventDefault(); myDropzone.processQueue(); }); Dropzone.autoDiscover = false; // Dropzone class: var myDropzone = new Dropzone("div#myId", { url: "/galleries", autoProcessQueue:false, headers: { 'X-CSRF-TOKEN': 'vjghjghjhgjghjghjghjgLxX', }, params: { 'brand': $('#brand').val(), 'url' : $('#url').val(), 'description': 'small detail' }, previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n " + "<div class=\"dz-image\"><img data-dz-thumbnail /></div>\n " + "<input type=\"text\" id=\"brand\" name=\"dz-brand\">\n " + "<input type=\"text\" id=\"url\" name=\"dz-url\">\n ..../div>" } );

im using dropzone to upload multiple images, and works fine, untill i want to insert a brand and url to each image.

The only issue im having is when im going to get the values from the input fields, im getting in myt request from the server undefined values from the fieds (brand, url) but if im using static text it appears no problem.

Here is my code:

$('#add').on('click',function(e){ e.preventDefault(); myDropzone.processQueue(); }); Dropzone.autoDiscover = false; // Dropzone class: var myDropzone = new Dropzone("div#myId", { url: "/galleries", autoProcessQueue:false, headers: { 'X-CSRF-TOKEN': 'vjghjghjhgjghjghjghjgLxX', }, params: { 'brand': $('#brand').val(), 'url' : $('#url').val(), 'description': 'small detail' }, previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n " + "<div class=\"dz-image\"><img data-dz-thumbnail /></div>\n " + "<input type=\"text\" id=\"brand\" name=\"dz-brand\">\n " + "<input type=\"text\" id=\"url\" name=\"dz-url\">\n ..../div>" } );

最满意答案

编辑:更新了所有这个答案:

您的ID不是唯一的,因此您无法可靠地从ID选择器获取输入数据。

将模板中输入的ID更改为以下类:

previewTemplate: "<div class='dz-preview dz-file-preview'>\n " + "<div class='dz-image'><img data-dz-thumbnail /></div>\n " + "<input type='text' class='dz-brand' value='This is the text'> \n " + "<input type='text' class='dz-url'>\n </div>"

然后使用发送事件添加参数,这将获得上载时的输入值。

myDropzone.on("sending", function(file, xhr, formData) { formData.append('brand' , $(file.previewElement).find('.dz-brand').val()); formData.append('url' , $(file.previewElement).find('.dz-url').val()); formData.append('description', 'small detail'); });

请参阅此处的文档: http : //www.dropzonejs.com/#event-sending

EDIT: Updated all of this answer:

Your Ids are not unique, therefore you can't reliably get the input data from the ID selector.

Change your IDs on your inputs in the template to classes like this:

previewTemplate: "<div class='dz-preview dz-file-preview'>\n " + "<div class='dz-image'><img data-dz-thumbnail /></div>\n " + "<input type='text' class='dz-brand' value='This is the text'> \n " + "<input type='text' class='dz-url'>\n </div>"

Then add the parameters with the sending event, this will get the input values at the time of upload.

myDropzone.on("sending", function(file, xhr, formData) { formData.append('brand' , $(file.previewElement).find('.dz-brand').val()); formData.append('url' , $(file.previewElement).find('.dz-url').val()); formData.append('description', 'small detail'); });

Refer to the Documentation here: http://www.dropzonejs.com/#event-sending

更多推荐

url,im,brand,电脑培训,计算机培训,IT培训"/> <meta name="description"

本文发布于:2023-07-15 05:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1110623.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   图像   adding   images   inputs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!