gpt4 book ai didi

javascript - 向图像添加字段(输入)

转载 作者:行者123 更新时间:2023-12-03 06:03:13 26 4
gpt4 key购买 nike

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

我遇到的唯一问题是,当我要从输入字段获取值时,我会从服务器获取来自字段(品牌、网址)的未定义值,但如果我使用静态文本,则似乎没有问题。

这是我的代码:

 $('#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

关于javascript - 向图像添加字段(输入),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39664685/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com