imbibinebe
unread,Mar 16, 2012, 11:52:23 AM3/16/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to JavaScript Templates Engine PURE
Hi,
My JSON data comes from a database and can look like this:
{
"users":
[
{"head1": "v11", "head2": "v12"},
{"head1": "v21", "head2": "v22"}
]
}
If I want to display the html table:
[ head1 ] [ head2 ]
[ v11 ][ v12 ]
[ v21 ][ v22 ]
with this html:
<table>
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
the following directive works nice:
{
"thead > tr > th":
{
"user1 <- users.0":
{
".":user1.pos
}
},
"tbody":
{
"user < users":
{
"tr > td":
{
"value <- user":
{
".":value
{
}
}
}
}
Now, unfortunatly, in some cases, the data might look like this:
[
{ 'head1':"v11" , 'head2': "v12"},
{ 'head1':"v21" , 'head2': "v22"}
]
No more 'users' property, it's only an array. I didn't find the good
directive (if it exists ;) to display the same table.
I tried this:
{
"thead > tr > th":
{
"fisrtline <- context.0":
{
".":fisrtline.pos
}
},
"tbody":
{
"line < context":
{
"tr > td":
{
"value <- line":
{
".":value
{
}
}
}
}
but it seems i can't access a single object with context.0 ...
does anyone have an idea ?