Search code examples
jqueryjquery-templatesjsrender

Can't read nested array json using JSRender


Can't read nested array json using JSRender

Code in this jsfiddle

I am getting

Error: Error: Cannot read property 'person' of undefined. Error: Cannot read property 'person' of undefined.

Anyone have an idea?


Solution

  • You have a line in there:

    {{for list.person.phones}}
    

    Which is already inside the person loop (so would be looking for a list object inside your person object), and doesn't match the layout of your data anyway, so it's causing the error. Change that block to:

    {{for numbers}}
        {{for phones}}
            <tr>
                <td>{{:name}}</td>
                <td>{{:number}}</td>
            </tr>
        {{/for}}
    {{/for}}
    

    and it works.