0

如何在 SCA(Handlebars)模板语言中嵌套 for 循环?

例如; 我有一个数组数组,我想遍历内部数组元素:

// Loop 1
{{#each footerNavigationLinks}}
<ul class="footer-content-nav-list">
    // Nested loop
    {{#each objectToAtrributes item}}
        <li>aa
        <a {{objectToAtrributes item}}>
                {{text}}
            </a>
        </li>
    {{/each}}
</ul>
{{/each}}

footerNavigationLinks是一个数组数组:

footerNavigationLinks: [
    [
        {text: 'Link a', href:'#'}
    ,   {text: 'Link b', href:'#'}
    ,   {text: 'Link c', href:'#'}
    ],
    [
        {text: 'Link a', href:'#'}
    ,   {text: 'Link b', href:'#'}
    ,   {text: 'Link c', href:'#'}
    ]
]
4

1 回答 1

0

不熟悉 SCA 提供的帮助程序(我认为 objectToAtrributes 就是其中之一),但我建议您嵌套的 #each 应该只是

{{#each this}}

因为那时你所拥有的只是一个数组。在嵌套的#each 中,应用“objectToAttributes”帮助器可能是有意义的,因为您现在正在使用数组中的每个对象。但是,如果这不起作用,我会尝试删除帮助程序,因为您应该已经可以访问没有它的“文本”属性。

于 2017-02-14T13:53:07.263 回答