How do I use nested iterators with Mustache.js or Handlebars.js?

后端 未结 6 1795
后悔当初
后悔当初 2020-12-24 01:52

I would like to use handlebars.js or mustache.js to iterate over a list of families, and then iterate over that family\'s members. Inside of both loops, I want to display pr

6条回答
  •  攒了一身酷
    2020-12-24 02:00

    I was looking for the same issue using mustache and the answers were given for handlebars, and the ones for mustache required extra JS, I know it is old but I'll add my working example just in case somebody else needs it. Cheers!

    JSON:

    "experience": [
         {
                "company": "Company 1",
                "position": "Graphic Designer",
                "tasks": ["Task 1", "Task 2", "Task 3"]
        },
         {
                "company": "Company 2",
                "position": "Graphic Designer",
                "tasks": ["Task 1", "Task 2", "Task 3", "Task 4", "Task 5"]
        }
    ]
    

    TEMPLATE:

    {{#experience}}
            

    {{company}}

    {{position}}
    Responsabilities
      {{#tasks}}
    • {{.}}
    • {{/tasks}}
    {{/experience}}

提交回复
热议问题