Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
Problema extraño con las variables Vue/Javascript

Honestamente, ni siquiera sé cómo buscar esta pregunta (qué parámetro de búsqueda escribir), pero de cualquier manera es un problema un poco extraño y estoy desesperado por obtener ayuda.

Entonces, estoy tratando de hacer algo simple, el evento envía "cambio de formulario" y cuando lo hace, establecemos un nuevo valor en el objeto "this.data" . Bastante simple. No espero que this.data sea reactivo, solo quiero actualizarlo.

 // Find our data object which we want to update/change if (form.field.includes('.')) { let find = form.field.split('.'), level = this.data; for (let index = 0; index < find.length; index++) { if (level[find[index]] !== undefined) { level = level[find[index]]; } else { level = undefined; } } if (level !== undefined) level = setFieldData(); }

Esto es bastante simple, tenemos el nombre del campo "inspeccionar.libro" y cuando llega la actualización (Evento), solo usamos puntos para dividir en varios árboles y actualizamos "este.datos.inspeccionar.libro" al nuevo valor. Pero no funciona. El valor no cambia.

Pero el valor de this.data.inspect.book real sale bien usando:

 console.log(level);

Sin embargo, si hago esto:

 this.data[ form.field.split( '.' )[ 0 ] ][ form.field.split( '.' )[ 1 ] ] = setFieldData();

Funciona bien. Entonces, la "referencia" a la variable no funciona ... ¿cómo es esto posible? ¿Parece un error en javascript o es algo con vue/reactividad?

¿Alguien tiene una mejor idea de cómo hacer que esto funcione?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Entonces, ¿está tratando de actualizar los datos del formulario usando la notación?

Yo haría algo así:

 _update(fieldName, value) { // We split segments using dot notation (.) let segments = fieldName.split("."); // We get the last one let lastSegment = segments.pop(); // We start with this.data as root let current = this.data if(current) { // We update current by going down each segment segments.forEach((segment) => { current = current[segment]; }); // We update the last segment once we are down the correct depth current[lastSegment] = val; } },

si tomo tu ejemplo:

 if (form.field.includes('.')) { let find = form.field.split('.'), level = this.data; for (let index = 0; index < find.length - 1; index++) { if (level[find[index]] !== undefined) { level = level[find[index]]; } else { level = undefined; } } if (level !== undefined) level[find.pop()] = setFieldData(); }

reemplacé find.length por find.length - 1 y reemplacé level = setFieldData() por level[find.pop()] = setFieldData()

debe actualizar la propiedad del objeto, sin anular el valor, porque si anula el valor, el valor original no se actualizará.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!