带把手模板的嵌套{{each}}循环 [英] Nested {{each}} loops with Handlebars template

查看:129
本文介绍了带把手模板的嵌套{{each}}循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试迭代对象数组,以便使用数组结构内的each循环将它们的值放在Handlebars模板中. 在这里,您可以看到数组:

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!

推荐答案

您正在使用几乎正确的语法:

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}}

当您处于#each循环中时,此对象将成为根"节点,因此您无需命名ph.fecha,而只需命名为fecha即可,因为ph是根.

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.

:我已更改名称fechaPH在您的示例中不存在,即fecha.

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

这篇关于带把手模板的嵌套{{each}}循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆