One row data over multiple TR's

33 views
Skip to first unread message

Sam Farmer

unread,
Apr 13, 2012, 6:00:58 PM4/13/12
to Pure-Unobtrusive...@googlegroups.com
All,

I have a row of data that needs to iterate over multiple tr's.

Data: 
var data = {
news:[
{ headline:'HEAD A', story:'aaaaaa'},
{ headline:'HEAD B', story:'bbbbbb'},
{ headline:'HEAD C', story:'cccccc'}
]
};

And the HTML:
<table border="1">
    <tbody>
        <tr class="line1">
            <td class="headline"></td>
        </tr>
        <tr class="line2">
            <td class="story"></td>
        </tr>
    </tbody>
</table>

(My actual template is a little more complicated but this is great for a sample).

When the directive is to just loop over tbody it works, but, adds a tbody around the two tr's which is not ideal.

Is there anyway to do this cleanly?

Thanks,

Sam

FULL CODE:



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"

<html lang="en">
<head>
<title></title>
</head>
<html>
<body>
<table border="1">
   <tbody>
       <tr class="line1">
           <td class="headline"></td>
       </tr>
       <tr class="line2">
           <td class="story"></td>
       </tr>
   </tbody>
</table>
<script>
var data = {
news:[
{ headline:'HEAD A', story:'aaaaaa'},
{ headline:'HEAD B', story:'bbbbbb'},
{ headline:'HEAD C', story:'cccccc'}
]
};

$p('table').render(data, {
'tbody':{
'row<-news':{
'td.headline':'row.headline',
'td.story':'row.story'
}
}
});
</script>
</body>
</html>

Mic (BeeBole)

unread,
Apr 14, 2012, 3:55:51 AM4/14/12
to JavaScript Templates Engine PURE
I had to do the same a while ago, and felt it was strange too.
But then I looked at the docs: http://www.w3.org/TR/html401/struct/tables.html#edef-TABLE
And saw that TBODY is meant to logically group TR.
And that it must exist(surprise) and can be multiple.

There is nothing dirty with your example..

Sam Farmer

unread,
Apr 14, 2012, 2:56:46 PM4/14/12
to pure-unobtrusive...@googlegroups.com
Awesome. Thanks Mic!

Sam

> --
> You received this message because you are subscribed to the Google Groups "JavaScript Templates Engine PURE" group.
> To post to this group, send email to Pure-Unobtrusive...@googlegroups.com.
> To unsubscribe from this group, send email to Pure-Unobtrusive-Rende...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/Pure-Unobtrusive-Rendering-Engine?hl=en.
>

Reply all
Reply to author
Forward
0 new messages