Skip to content Skip to sidebar Skip to footer

How To Render Array Of Arrays Of Objects With Mustache

I am trying to render an array of arrays of objects with a mustache template in javascript, and I have not found anyone else who has asked this question. I can render an array of o

Solution 1:

This question is 2 years old but I guess better late than never. You can use {{.}} to reference the current element in an array.

context = [
    [
        { id: 12345, name: "Billy" },
        { id: 23456, name: "Joe" },
        { id: 34567, name: "Jenny" }
    ],
    [
        { id: 45678, name: "Amy" },
        { id: 56789, name: "Julie" },
        { id: 67890, name: "Sam" }
    ]
]

template = "
    {{#context}}
        {{#.}}
            <span id={{id}}>{{name}}</span>
        {{/.}}
    {{/context}}
"

Post a Comment for "How To Render Array Of Arrays Of Objects With Mustache"