【问题标题】:Assemble (templates): Get parent value from within nested each block组装(模板):从嵌套的每个块中获取父值
【发布时间】:2015-03-13 21:17:10
【问题描述】:

我在从父循环/每个循环中获取值时遇到问题。我该怎么做?

我正在遍历一些问题,然后遍历一些答案。我想在每个答案中添加问题 ID..

JSON:

{
    "questions": [
        {
            "id": 1,
            "answers": [
                ...
                ...
                ...
            ]
        }
    ]

}

Assemble.io 嵌套循环/每个

{{#forEach questions}}
    <h2>{{id}}</h2>
    <ul>
        {{#forEach this.answers}}
            <li>
                <input type="radio" name="{{id}}" id="{{id}}-{{index}}"/>
            </li>
        {{/forEach}}
    </ul>
{{/forEach}}

你知道我如何从父循环/每个循环中获取 ID 吗?

提前谢谢你... :-)

【问题讨论】:

    标签: html handlebars.js assemble grunt-assemble


    【解决方案1】:

    在车把中,您可以使用parent accessor syntax ../

    {{#forEach questions}}
        <h2>{{id}}</h2>
        <ul>
            {{#forEach this.answers}}
                <li>
                    <input type="radio" name="{{../id}}" id="{{../id}}-{{index}}"/>
                </li>
            {{/forEach}}
        </ul>
    {{/forEach}}
    

    【讨论】:

    • 太棒了!不敢相信我没有找到那个。谢谢!
    猜你喜欢
    • 2021-10-27
    • 1970-01-01
    • 2013-07-22
    • 1970-01-01
    • 2020-02-19
    • 2017-04-01
    • 1970-01-01
    • 2019-12-18
    • 2010-12-26
    相关资源
    最近更新 更多