Search code examples
jqueryjquery-templates

jQuery templates - Rendering out generic json object


I'm trying to create a generic template which will render out JSON objects. The problem is, with all the samples I have seen, they are based on knowing the names of the key...

I started off trying something like this:

<table>
    {{each}}
    <tr>
        <td>$($value[0]}</td><td>$($value[1]}</td>
    </tr>
    {{/each}}
</table>

Now I this isn't generic yet but I was trying this as a start, but it doesn't work...


Solution

  • This was not apparent to me either.

    <table>
         <tr>
            {{each $data}}
            <td>${ $index }</td><td>${ $value }</td>
            {{/each}}
         </tr>
    </table>
    

    But when you see it you have a D'OH moment.