Two dimenstional array not working inside <script> tag



  • When passing the two-dimensional array is not working inside <script> tag and it is automatically converted to a string.

    Orginal Data from API : [[1656558660000,1082],[1656558720000,16000],[1656558780000,53311],[1656558840000,112095],[1656558900000,193935]]

    Actual Result getting when passing the data inside script tag: 1656558660000,1082,1656558720000,16000,1656558780000,53311,1656558840000,112095,1656558900000,193935

    Expected result : two-dimensional array as it is Orginal Data from API
    [[1656558660000,1082],[1656558720000,16000],[1656558780000,53311],[1656558840000,112095],[1656558900000,193935]]



  • There shouldn't be some flattening happening.
    Could you please provide a minimal playground replicating the problem?
    Thank you



  • I am also experiencing the same thing.

    Check my sample report: https://playground.jsreport.net/w/aquater08/2Dtg2~r9
    Replace the binding with the same value from the data template to see the difference.

    Background: The value of the every element should be [y, x]. However, when binding the data, the array becomes a single array [y].

    Is there a workaround for this?

    Thanks.



  • The problem is described in this older but still valid post
    https://jsreport.net/blog/using-input-data-in-html-page-inline-javascript

    jsrender/handlebars isn't doing JSON serialization when you do this
    data: [{{:Testdb5dcd55106b4e82b79932720bcea516}}]
    but it's own "to text" serialization so you end with this
    data: [43934,11744,52503

    The solution mentioned in the post works well, but jsreport has since v3 already system helper for you.
    https://jsreport.net/learn/templating-engines#tojs-data-

    data: {{:~toJS(Testdb5dcd55106b4e82b79932720bcea516)}}
    

    Hint: I like to use text recipe for troubleshooting to see whats exactly is printed by handlebars before being evaluated by chrome.



  • jan_blaha. ~toJS worked! Thank you!


Log in to reply
 

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