【问题标题】:mandrill - handlebars how can i iterate over 2 dimension array?mandrill - 车把我如何迭代二维数组?
【发布时间】:2015-12-29 21:30:03
【问题描述】:

假设我有这个数组:

var arr = [
    [1,4,6,8,3,9,1],
    [2,4,6,7,3,2,7]
];

我想用 mandrill 迭代它 -> 车把 #each 我该怎么做?

到目前为止,我有类似的东西

{{#each arr}}
    {{#each this}}
        {{this}}
    {{/each}}
{{/each}}

上面将输出所需的结果,但是当我在第二个中添加一个条件时,每个 this 值都会更改为一个数组,我假设它需要父级 - 不确定。

{{#each arr}}
    {{#each this}}
        {{#if @first}}
            <div>{{this}} - first</div>
        {{else}}
            <div>{{this}}</div>
        {{/if}}
    {{/each}}
{{/each}}

当我使用普通车把时,它工作得非常好。 例如。 http://jsfiddle.net/ccrmwont/2/

我知道这是一个非常具体的问题,但我已经坚持了 2 天了。

【问题讨论】:

    标签: javascript handlebars.js mandrill


    【解决方案1】:

    您应该在第二次迭代中使用索引:

    {{#each arr}}
    {{#each 0}}
        {{#if @first}}
            <div>{{0.0}} - first element in first array</div>
            <div>{{0.1}} - second element in first array</div>
    {{/each}}
    {{#each 1}}
            <div>{{1.0}} -first element in second array</div>
            <div>{{1.1}} -second element in second array</div>
    {{/each}}
    {{/each}}
    

    我认为 Mandrill 还不支持完整的车把功能,这可能是目前最好的方法。在这里查看更多:

    https://mandrill.zendesk.com/hc/en-us/articles/205582537-Using-Handlebars-for-dynamic-content

    【讨论】:

      猜你喜欢
      • 2021-06-16
      • 1970-01-01
      • 2016-03-30
      • 2011-12-28
      • 2015-04-04
      • 2014-05-30
      • 2020-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多