christopherdro / react-native-html-to-pdf

Convert html strings to PDF documents using React Native
MIT License
434 stars 264 forks source link

Pass data to script tag inside html content #281

Closed prox2 closed 2 years ago

prox2 commented 2 years ago

Hi, I am passing data into html content and it is displaying an working fine, besides that i have array of data where will be rendered in table and to do that i have added <script> before the end of the body and i implemented for loop as follow:

.....
 <script>
    var trs = '';
    var RowsData = ${data.RowsData};
    for (var i = 0; i <= RowsData.length; i++) {
      trs += '<tr>  <td> i.balance </td> <td> i.ForAmount</td>  <td> i.FromAmount</td>  <td> i.Note</td> <td>i.Date </td> <td> i.id</td> </tr>'

    }
    document.getElementById('rowsData').insertAdjacentHTML('afterbegin', trs);
    </script>
  </body>

</html>

But the issue is that the var RowsData is always empty and data is not rendered as <tr> I have tried to put the script within the <head> but still not working.

when i assign data to var RowsData directly not from props passed, it works fine.

I don't know how to make this work. i hope someone can help or have workaround for this.

rkchoudhury commented 1 year ago

@prox2: Did you find any solution for this? How to render dynamic contents in the pdf?