var myVar = {{{toJSON someData}}}; not working



  • hi,

    in my project, there is script file getting data from an api.

    result.on('end', () => {
               req.data.apiData = JSON.parse(str);
               done();
           })
    

    and in report template there is this code below.

    <script>
    var reportData = {{{toJSON apiData}}};
    
    {#asset /assets/js/my.js @encoding=utf8}
    </script>
    

    in toJSON method if I console log I see the data passed from script.

    but the var reportData part seems not working.
    and in my.js file I cannot reach reportData properties.

    this usage was working. but now does not work.
    I just changed the folder jsreport is running.

    what might be the problem?



  • I also tried printing the json to a div. I see it printed corectly.

    <div id="rptData" style="display:none">{{{toJSON apiData}}}</div>
    

    but I also can't get the innerHTML of that div...

    <script>
    var reportData = JSON.parse(document.getElementById("rptData").innerHTML);
    
    {#asset /assets/js/my.js @encoding=utf8}
    </script>
    


  • Don't see a problem at the first glance.
    How does the toJSON look like?
    Are you able to replicate the problem in the playground?
    https://playground.jsreport.net/



  • toJSON is this function.

    function toJSON(data) {
      return JSON.stringify(data);
    }
    

    I can't prepare sample in public space, report is confidential.



  • do you block some features, that can cause this issue on trial?

    2020-10-14T07:39:04.089Z - info: Verifying license key free
    2020-10-14T07:39:05.764Z - info: Using enterprise trial license



  • I can't prepare sample in public space, report is confidential.

    Please create just minimal workspace that replicates the problem. We don't need to see any values or styles...

    do you block some features, that can cause this issue on trial?

    No, this has nothing to do with licensing.



  • when I check the assets files in disk,
    I saw that some js assets are uploaded as content.html instead of content.js

    I deleted all the js assets and re added them and it is working now.

    what may cause these assets upload as content.html instead of content.js?



  • We use the file extension from the file you upload.
    So if you upload a foo.js, the file on the disk should be content.js.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.