带有 Handlebars 模板的嵌套 {{each}} 循环

Jua*_* TM 3 templates json handlebars.js

我试图迭代一个对象数组,以便使用数组结构内的 each 循环将它们的值放入 Handlebars 模板中。在这里你可以看到数组:

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'
            ],
        
        ],
        
    }
];
Run Code Online (Sandbox Code Playgroud)

如您所见,如果尝试过每个循环:

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

{{/each}}
Run Code Online (Sandbox Code Playgroud)

我不知道如何解决它或我做错了什么。我感谢有关此问题的任何评论 非常感谢!

Chr*_*phe 5

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

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

{{/each}}
Run Code Online (Sandbox Code Playgroud)

当您在 #each 循环中时,此对象将成为“根”节点,因此您无需命名 ph.fecha,而只需将 fecha 命名为 ph 是根。

[编辑]:我更改了名称 fechaPH 在您的示例中不存在它是 fecha。