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

152
Views
¿Cómo puede convertir una List<Pair<String,String>> a List<String> en javascript?

Esta es la salida: la estructura de datos para la salida es Map<String, List<Pair<String, String>>>

 "testdata": [ { "1.0": "True" }, { "1.1": "False" } ]

Ahora necesito mostrar estos datos en la interfaz de usuario como "testdata":["1.0","1.1","1.2"] , donde aquí del Par, quiero obtener solo los primeros elementos del Par y ponerlos la estructura Map<String, List<String>>

Entonces, ¿cómo escribo ese código en javascript para obtener ese resultado?

 this.previousData = versions.filter(v => v !== this.version).map(item => ({ text: item, value: item }))

¿Cómo modifico este código para obtener esta salida "testdata":["1.0","1.1","1.2"] ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

su pregunta no es muy clara sobre con qué elemento está luchando

así que para obtener los datos

 async getData() { const resp = await fetch("<<your url from your java service>>" ) return await resp.json(); }

para formatear los datos como usted desea que sean formateados

 formatData(json){ return json.testdata.map((i)=>Object.entries(i).map(([k,v])=>k)).flat() }

y para mostrar en vue

 <template>testdata:{{testdata}}</template> <script> ... methods:{ async populatedata(){ const tmp = await getData() this.testdata = formatData(tmp) } } ... </script>

Object.entries convertirá un objeto en una matriz de tuplas, por lo que {"1.0":"True","1.1":"False"} se convertirá en [["1.0","True"],["1.1":"False"]] que luego le permite usar la descomposición de tuplas para obtener las claves

también podría usar Object.keys() si no necesita los valores, pero eso no estaba claro en el contexto, así que le di la opción más flexible

about 4 years ago · Juan Pablo Isaza Report

0

Podrías intentar algo como esto:

 // This assumes that there will be only one key in each array item, or the first key in each array item denotes the version this.previousData = versions .filter(v => v !== this.version) .map(item => Object.keys(item)[0]) // or as MikeT suggested, if you are only expecting something like this: // [ // { "v1": "some value 1" }, // { "v2": "some value 2" }, // ... in general --> { "version": "some value" } // ] // you may try this as well this.previousData = versions .filter(v => v !== this.version) .map(item => Object.keys(item)) .flat()
about 4 years ago · Juan Pablo Isaza 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!