Javascript 具有输入值的重复对象

Javascript 具有输入值的重复对象,javascript,node.js,object,mongoose,Javascript,Node.js,Object,Mongoose,我有一个创建表单的javascript转发器, 但问题是,当我把价值观​​它们都是在单个对象中输入的,而不是在单独的对象中输入的,这些对象在数组位置中应创建类似的结构 "locations":[ { "coordinates":[ -80.128473, 25.781842 ], "description&qu

我有一个创建表单的javascript转发器, 但问题是,当我把价值观​​它们都是在单个对象中输入的,而不是在单独的对象中输入的,这些对象在数组位置中应创建类似的结构

"locations":[
        {
           "coordinates":[
              -80.128473,
              25.781842
           ],
           "description":"Lummus Park Beach",
           "day":1
        },
        {
           "coordinates":[
              -80.647885,
              24.909047
           ],
           "description":"Islamorada",
           "day":2
        },
   ]
我的代码从输入中获取信息,但将其放在同一个对象中,而不是单独的对象中

//这是在对象结构中获取输入值和插入值的代码
const createTour_form=document.querySelector('.form-create__tour');
如果(createTour_表单){
createTour_form.addEventListener('submit',(cr)=>{
cr.preventDefault();
//创建一个空数组
设loc_坐标=[];
让loc_description=[];
让loc_day=[];
让get_locations=[];
//获取坐标
document.querySelectorAll(“.location\u field\u card”).forEach(f=>{
设obj=[];
f、 queryselectoral(“.location\u new\u tour”).forEach(ele=>obj[ele.value]=ele.value | | |“”);
loc_坐标推(对象键(obj));
});
//获取描述
document.querySelectorAll(“.location\u field\u card”).forEach(f=>{
设obj1={};
f、 queryselectoral(“.description_location”).forEach(ele=>obj1[ele.name]=ele.value | | |“”);
位置描述推送(obj1)
});
//有一天
document.querySelectorAll(“.location\u field\u card”).forEach(f=>{
设obj2={};
f、 queryselectoral(“.location_day”).forEach(ele=>obj2[ele.name]=ele.value | | |“”);
loc_日推送(obj2)
});
//反向坐标
const getGeo=[…loc_坐标].toString().split(',').reverse().join('').replace('',');
获取位置。推送(getGeo)
const getLocation=Object.values(…loc_description);
const getValLocation=getLocation.toString();
const getDay=Object.values(…loc_day);
const getValDay=parseInt(getDay.toString());
让getTotaLocation=新对象({
“坐标”:[…获取位置],
“描述”:getValLocation,
“天”:getValDay
});
log(getTotaLocation);
})
}

位置
位置

位置描述

一天

添加位置字段 创建旅游 const addLocation=document.getElementById('add_location_fields'); 如果(添加位置){ 让count_createdCards=0; 让count_Deletebutton=0; 设递增函数=0; addLocation.addEventListener('单击',(st)=>{ 圣彼得堡(); 让createAddField=document.getElementById('add_location_field'); //Crd count_createdCards++; 计数按钮++; 递增函数++; 让card=document.createElement('div'); setAttribute('class','location\u field\u card'); card.setAttribute('id','delete_card_'+count_createdCards) //第一张卡片标题 让cartitle1=document.createElement('p'); cartitle1.setAttribute('class','subfield\u natours\u create\u tour'); cartTitle1.textContent='Location'; 让inputLocation=document.createElement('input'); inputLocation.classList.add('form_uinput'); inputLocation.classList.add('location\u new\u tour'); setAttribute('type','text'); setAttribute('value','24.5647846,-81.8068843'); //第二张卡片标题 让cartitle2=document.createElement('p'); cartitle2.setAttribute('class','subfield\u natours\u create\u tour'); cartTitle2.textContent='位置描述'; 让inputDescription_location=document.createElement('input'); inputDescription\u location.classList.add('form\u input'); inputDescription\u location.classList.add('description\u location'); inputDescription_location.setAttribute('type','text'); inputDescription_location.setAttribute('value','Lummus Park Beach'); //第三张卡片标题 让cartitle3=document.createElement('p'); cartitle3.setAttribute('class','subfield\u natours\u create\u tour'); cartTitle3.textContent='Day'; 让inputDescription_day=document.createElement(“输入”); inputDescription\u day.classList.add('form\u input'); inputDescription_day.classList.add('location_day'); inputDescription_day.setAttribute('type','number'); inputDescription_day.setAttribute('value','1'); 让removeButton=document.createElement('a'); removeButton.classList.add('btn'); removeButton.classList.add('btn--small--add'); removeButton.classList.add('btn--red'); setAttribute('onclick','removeAction'+count\u Deletebutton+'()'); 让removeScript=document.createElement('script'); removeScript.innerHTML=“函数removeAction”.concat(count\u Deletebutton,”({\n\n var delCard_uux”) .concat(incrementFunction,“=document.getElementById(\”删除
  //Increment Coordinates
   let incrementCoordiantes = 0; 
   //Increment Description
   let incrementDescription = 0; 
   //Increment Day
   let incrementDay = 0;

 addLocation.addEventListener('click',(st)=>{
           let createAddField = document.getElementById('add_location_field');
    
     incrementCoordiantes ++;
     incrementDescription ++;
     incrementDay ++;
     let card = document.createElement('div');
       ......
       inputLocation.setAttribute('id','getCoordinates_'+ incrementCoordiantes);
       inputDescription_location.setAttribute('id','getDescription_' + incrementDescription);
       inputDescription_day.setAttribute('id','getDay_' + incrementDay );
   const push_location_data = [];
      const getAll_locations =  document.querySelectorAll(".location_field_card");
      for (let i=1; i< getAll_locations.length; i++) {

    let cord_lat_lng = 'getCoordinates_' + i;
    let cord_description = 'getDescription_' + i;
    let cord_day = 'getDay_' + i;

    let dinamic_obj = {
        coordinates:[[document.getElementById(cord_lat_lng).value].toString().split(',').reverse().join(' ').replace(' ', ' ,')],
        description:document.getElementById(cord_description).value,
        day:document.getElementById(cord_day).value
    }
  

    push_location_data.push(dinamic_obj);
};