Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
How add a list variable in html string?

Currently I am using an html string to create a pdf. In that html string I need to pass a list variable. The problem is I need to create a table using that list variable. But when I try to assign it to a variable inside the script parameter in the html string its not getting assigned.

let amountList= [
      { name: 'store Amount', amount: 0 },
      { name: 'reinventAmount', amount: 0 },
      { name: 'Cost Amount', amount: 90 },
      { name: 'Total Amount', amount: 90 }
    ];


let htmlStringUsedforPdf= `<html>
<body>
  <table>
      <thead>
     </thead>
     <tbody class="sub-text" id="testBody"></tbody>
    </table>
  <script>
      
  
    function loadTableData(items) {
      const table = document.getElementById("testBody");
     
    
      items.forEach( item => {
        let row = table.insertRow();
        let name= row.insertCell(0);
        name.innerHTML = item.name;
        let amount= row.insertCell(1);
        amount.innerHTML = item.amount;
      });
    }
    loadTableData(${amountList});
    
  </script>

<body>
</html>`

The table is created without the amountList data. 
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Was able to sort out the problem by stringifying the list. Seems like it was not getting assigned because html was a string. Solution was

amountList = JSON.stringify(amountList)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda