Loop through object properties nunjucks

前端 未结 2 1389
广开言路
广开言路 2021-02-13 12:40

I\'ve got following model:

items: {
    someId1: 
        {
            property1....
        },
    someId2: {...},
    someIdN: {...}
}

I wou

2条回答
  •  心在旅途
    2021-02-13 13:22

    This answer is actually right on the Nunjucks homepage:

      {% for name, item in items %}
    • {{ name }}: {{ item }}
    • {% endfor %}

    In your case this would be:

      {% for someId, item in items %}
    • {{ someId }}: {{ item.property1 }}
    • {% endfor %}

    As you can use the for loop for arrays and object/hashes.

提交回复
热议问题