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

160
Views
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 answers
Answer question

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 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!