I'm starting with node expressjs framework and I came across this problem I can't solve.
I'm trying to display a table with some blog posts (yes, a blog...) but I don't get it done.
This is the Jade template code:
div
table
thead
tr: th Posts
tbody
each post, i in userPosts
tr(class=(i % 2 == 0) ? 'odd' : 'even'): a(href='/admin/post/' + post.id) #{post.author} - #{post.title}
And this is the HTML output:
<div>
<a href="/admin/post/1">Post 1</a>
<a href="/admin/post/2">Post 2</a>
<a href="/admin/post/3">Post 3</a>
<table>
<thead>
<tr>
<th>Posts</th>
</tr>
</thead>
<tbody>
<tr class="odd"></tr>
<tr class="even"></tr>
<tr class="odd"></tr>
</tbody>
</table>
</div>
So, any ideas?
I found that the problem was that I was missing the TD tag for each TR. So the jade code should be like this:
div
table
thead
tr: th Posts
tbody
each post, i in userPosts
tr
td
a(href='/admin/post/' + post.id) #{post.author} - #{post.title}
try this
div
table
thead
tr: th Posts
tbody
each post, i in userPosts
tr(class=(i % 2 == 0) ? 'odd' : 'even')
td
a(href='/admin/post/' + post.id) #{post.author} - #{post.title}
With current pug version didn't work for me. Instead I modified the code to the following pattern:
div
table
thead
tr
th title...
tbody
each post in userPosts
tr
td= post.author
td= post.title
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With