【发布时间】:2017-09-03 05:28:15
【问题描述】:
鉴于这种情况
{
letters: ['a', 'b', 'c'],
numbers: ['1', '2', '3']
}
我将如何制作
a1
a2
a3
b1
b2
b3
c1
c2
c3
本质上,
{{#each letters}}
{{#each ../numbers}}
what to put here?
{{/each}}
{{/each}}
我专门使用https://github.com/sunng87/handlebars-rust,但是理论上这非常接近功能奇偶性,因此在handlebars.js中的实现方式应该是兼容的。
作为参考,我的实际用例是 C++ 代码生成。问题主要是关于访问内部循环的 this 属性。现在我的代码看起来像
{{#each variant}}
{{#each ../typearg}}{{#if @first}}template <{{/if}}{{this}}{{#if @last}}>{{else}},{{/if}}{{/each}}
{{/each}}
但是由于某种原因,这个输出
template <>
template <>
当我期望它输出时
template <T>
template <T>
相关的对象以形式传递给它
{
typearg: [ 'T' ],
variant: [{ }, { }]
}
【问题讨论】:
-
看起来像一个嵌套的
#each循环,外部带有letters,可以做到。 -
有没有办法维护嵌套结构?
-
请添加
handlebars-rust作为标签,尤其是在您基于此问题创建错误报告时。 -
我为你添加了它,因为我不相信你有能力使用新标签来做到这一点
标签: javascript handlebars.js each