Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested {{each}} loops with Handlebars template

Im trying to iterate an Array of Objects for putting their values in a Handlebars template using the each loop inside the structure of the array. Here you can see the array:

var datosSensores = [    
    {
        name:'John Pinard',
        email:'[email protected]',
        ph: [
            '7.80',
            '7.90',
            '7.60',
            fecha: [
                '2016-06-20 09:00',
                '2016-06-21 10:00'
            ],
        
        ],
        
    }
];

And the each loop if've tried as you can see:

{{#each ph}}
....
.....
    {{#each ph.fechaPH}}
        {{this.fechaPH}} //This would be the value of each DATE in the array
    {{/each}}  

{{/each}}

I dont know how to solve it or what I'm doing wrong. I appreciate any comment about this issue Thanks a lot!

like image 636
Juan Pablo TM Avatar asked Aug 31 '26 13:08

Juan Pablo TM


2 Answers

You're almost using the correct syntax :

{{#each ph}}
....
.....
    {{#each fecha}}
        {{this}} //This would be the value of each DATE in the array
    {{/each}}  

{{/each}}

When you're inside a #each loop the this object becomes the "root" node so you don't need to name ph.fecha but just fecha as ph is the root.

[Edit] : I've changed the name fechaPH does not exist in your example it is fecha.

like image 85
Christophe Avatar answered Sep 03 '26 02:09

Christophe


{#each main}}  
  {{#each sub}} 
    <p>{{ ../dataOfMain }}</p>
    <p>{{ subData }}</p>
  {{/each}}
{{/each}}
like image 34
Shuhaib zahir Avatar answered Sep 03 '26 02:09

Shuhaib zahir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!