Javascript 更改输入类型=";文件";从数组中获取值的步骤

Javascript 更改输入类型=";文件";从数组中获取值的步骤,javascript,html,jquery,forms,Javascript,Html,Jquery,Forms,在将图像输入数据库之前,我使用js显示用户的图像,然后再将它们添加到数据库中,这是我设法做到的。 但我还想添加一个功能,可以删除某些图像 我有一个输入type=“file”,从中插入电脑中的数据 选择照片 为了添加雨刮器功能,我们将输入数据存储在一个对象数组中,我创建了一个新的数组,在其中存储我要删除的数据,然后使用array.filter来分离信息 $this.data('delimg'); -> <div class="delete_image_output"

在将图像输入数据库之前,我使用js显示用户的图像,然后再将它们添加到数据库中,这是我设法做到的。 但我还想添加一个功能,可以删除某些图像

我有一个输入type=“file”,从中插入电脑中的数据

选择照片

为了添加雨刮器功能,我们将输入数据存储在一个对象数组中,我创建了一个新的数组,在其中存储我要删除的数据,然后使用array.filter来分离信息

$this.data('delimg'); -> <div class="delete_image_output" data-delimg="0">x</div>
最后,我设法用选定的图像创建了一个数组,但在数据库中保存信息时出现了问题

但是我如何更改下面结构中的代码,而不是从输入中获取值,从而从上面的数组中获取值呢

let createPost = document.querySelector('.createNew--post--creativePoint');
if(createPost){
createPost.addEventListener('submit',(crPos)=>{
    crPos.preventDefault();

    let filesImg = document.getElementById('creative---Point19981022--newPostPhoto').files;
    const postData = new FormData();
        postData.append('title',document.getElementById('creative---Point19981022-create--newPostTitle').value);
        postData.append('link',document.getElementById('creative---Point19981022-create--newPostLink').value);
        postData.append('description',document.getElementById('creative---Point19981022--newPostDescription').value);
        postData.append('datePost',document.getElementById('creative---Point19981022--dataNow').value);
        // Using For loop for miltiple images
        for (let p = 0; p < filesImg.length; p++) {
            postData.append('images', filesImg[p]);
        }
        postData.append('youtubeEmbedVideo',document.getElementById('creative---Point199810022-create-embedIdOnly').value);
        postData.append('author',document.getElementById('creative---Point19981022--authorDate').value);
    
    // Do not allow posts if all fields al empty
    if( document.getElementById('creative---Point19981022-create--newPostTitle').value != "" || 
        document.getElementById('creative---Point19981022--newPostPhoto').files.length != 0  || 
        document.getElementById('creative---Point19981022-create--newPostLink').value  != "" ||
        document.getElementById('creative---Point19981022--newPostDescription').value  != "" ||
        document.getElementById('creative---Point199810022-create-embedIdOnly').value  != ""){
            //createPostFnc(postData);
            console.log(filesImg)
    }else{
        showAlert('error',' No field was filled in, the post cannot be processed');
    }    
});
let createPost=document.querySelector('.createNew--post--creativePoint');
如果(createPost){
createPost.addEventListener('submit',(crPos)=>{
crPos.preventDefault();
让filesImg=document.getElementById('creative--Point19981022--newPostPhoto').files;
const postData=new FormData();
append('title',document.getElementById('creative--Point19981022 create--newPostTitle').value);
append('link',document.getElementById('creative--Point19981022 create--newPostLink').value);
append('description',document.getElementById('creative--Point19981022--newPostDescription').value);
append('datePost',document.getElementById('creative--Point19981022--dataNow').value);
//用于多重图像的For循环
for(设p=0;p

filesImg而不是输入值从数组中获取值并调整结构

因此,如果我理解正确,您希望发送一个经过筛选的文件数组,而不是
输入选择的所有文件

我会尝试使用一个on
filesImg
来检查“过滤数组”是否为空

let filesImg = (arrayImg.length>0) ? arrayImg : document.getElementById('creative---Point19981022--newPostPhoto').files;
您必须在全局范围内声明
arrayImg
,就像对
prepareArrayList
所做的那样

let filesImg = (arrayImg.length>0) ? arrayImg : document.getElementById('creative---Point19981022--newPostPhoto').files;