• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

130
Views
Acceso a un objeto de un objeto

Estoy usando el complemento Datamaps y estoy tratando de acceder a un objeto que está en otro objeto.

Aquí quiero obtener todos los valores de data en options . Consulte la respuesta de console.log en la captura de pantalla a continuación.

Aquí está el js:

 var map = new Datamap({ scope: "fra", element: document.getElementById("map-france"), responsive: true, fills: { defaultFill: "#EDE8D6", "1-50": color_dept[4], "51-100": "#EDE8D6", "101-150": "#E2DABF", "151-200": "#CEC191", "201-300": "#BCAE7C", "301-400": "#9D893E", "401-": "#827131", }, data: { YV: { fillKey: "#EDE8D6", }, AM: { fillKey: "51-100", }, }, geographyConfig: { popupTemplate: function (geo, data) { for (const val of uniqueValues) { if (geo.properties.name == val) { return [ '<div class="hoverinfo"><strong>', val, "<br/>", dataValues.filter((v) => v == val).length, " parrainages", "</strong></div>", ].join(""); } } }, hideAntarctica: true, hideHawaiiAndAlaska: false, borderWidth: 1, borderOpacity: 1, borderColor: "#D2D3B5", popupOnHover: true, // True to show the popup while hovering highlightOnHover: true, highlightFillColor: "#1E2382", highlightBorderColor: "#FFFFFF", highlightBorderWidth: 1, highlightBorderOpacity: 1, }, setProjection: function (element) { var projection = d3.geo .mercator() .center([2.454071, 46.279229]) .rotate([0, 0]) .scale(1700) .translate([350, 225]); var path = d3.geo.path().projection(projection); return { path: path, projection: projection, }; }, }); Object.entries(map).map((item) => { console.log("item 1 : ", item); });

ingrese la descripción de la imagen aquí

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Ex.

 const mapExample = new Map() mapExample.set("test", {"nestedObj":{"newObject":"new Obj value"}})

ahora, mapear sobre esto le daría una matriz con el objeto de nivel superior "prueba"

para obtener el valor del valor anidado de "newObject":

 Object.entries(mapExample.get("test")).map(i=> console.log(i[1].newObject))

o

 Object.entries(mapExample.get("test")).map(i=> { let [key,value] = i console.log(key,value) });

puede copiar y publicar esto en la consola de Chrome y jugar con él, para ver diferentes resultados.

pero la forma de tomar la clave es Object.entries devuelve una matriz de su Objeto en orden ["clave":"valor"].

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error