Nested {{each}} loops with Handlebars template

两盒软妹~` 提交于 2019-12-08 10:39:46

问题


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:'jp@aol.com',
        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!


回答1:


You're using almost 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.



来源:https://stackoverflow.com/questions/44805977/nested-each-loops-with-handlebars-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!