mandrill - 把手如何迭代2维数组?

时间:2020-11-30 21:32:40

Say I have this array:

说我有这个数组:

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

And I want to iterate over it with mandrill -> handlebar #each how will I do it ?

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

so far I have something like

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

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

the above will output the desired result but when I add a condition inside the second each this value changes to an array I assume it takes the parent this - not sure.

以上将输出所需的结果但是当我在第二个中添加一个条件时,这个值变为一个数组我假设它接受父项 - 不确定。

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

More over when I use normal handlebars it works perfectly fine. E.G. http://jsfiddle.net/ccrmwont/2/

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

This is pretty specific issue I know but I am stuck with this for 2 days now.

这是我所知道的非常具体的问题,但我现在坚持了2天。

1 个解决方案

#1


0  

you should use the index in your second iteration:

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

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

I dont think Mandrill yet supports full handlebars functionality, this is probably the best way to do this at the moment. See more here:

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

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

#1


0  

you should use the index in your second iteration:

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

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

I dont think Mandrill yet supports full handlebars functionality, this is probably the best way to do this at the moment. See more here:

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

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