Looping an array inside its neighboring array



  • So i have 2 arrays and i want to print Array2 inside of Array1

    {
        "Array1":[
           {
             "item1": "1-arr1 item1",
             "item2": "1-arr1 item2",
           },
           {
             "item1": "2-arr1 item1",
             "item2": "2-arr1 item2",
           }
        ],
    
        "Array2":[
           {
             "something1": "1-arr2 something1",
             "something2": "1-arr2 something2",
           },
           {
             "something1": "2-arr2 something1",
             "something2": "2-arr2 something2",
           }
        ]
    }
    

    i have tried:

    {{#each Array1}}
       <span> {{item 1}} </span>
       <span> {{item 2}} </span>
       {{#each Array2}}
          <span> {{something1}} </span>
          <span> {{something2}} </span>
       {{/each}}
       <br></br>
    {{/each}}
    

    and it doesn't work and just gives me an empty Array2 loop.
    which looks like this:

    1-arr1 item1
    1-arr1 item2
    
    2-arr1 item1
    2-arr1 item2
    

    How can I make it so that my output would look like this:

    1-arr1 item1
    1-arr1 item2
    1-arr2 something1
    1-arr2 something2
    2-arr2 something1
    2-arr2 something2
    
    
    2-arr1 item1
    2-arr1 item2
    1-arr2 something1
    1-arr2 something2
    2-arr2 something1
    2-arr2 something2
    


  • Please check the handlebars documentation for the details of how the context works:
    https://handlebarsjs.com/guide/expressions.html#basic-usage

    In your case, you probably want to use the following, to reach the Array2 in the parent scope

    {{#each ../Array2}}
    


  • Thank you sir!


Log in to reply
 

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