P
P
Pavel2014-08-11 23:32:55
Node.js
Pavel, 2014-08-11 23:32:55

Jade, how to display the field of an object?

An array of objects is passed to the jade template, then the objects themselves are enumerated, which have the following structure:

{ _id: 53e91147ce282615c3f61423,
  author: 'Автор Имя',
  title: 'Заголовок',
  date: '09.02.2013',
  genre: 'жанр',
  genre_id: 2 }

Output Code
-var t = ""
pre #{verses[0]}
-for verse in verses
  ul
    -if(t != verse.author)
      -var t = verse.author
        span.author #{verse.author}

      li 
        span
          a(href='/verse/'+verse.id) #{verse.title}
          span #{verse.genre_id}
          a(href='/verse/find/'+verse.genre_id) #{verse.genre}

All fields are displayed correctly, except for genre_id, when the entire object is displayed, it is, but when the genre_id itself is displayed, I get undefined. What could be the problem? And how to decide?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikolai, 2014-08-14
@j_wayne

Try outputting verse.genreId. I'm not sure, but this is the first thing I would try, since this is the main difference from other attributes

F
felixexter, 2014-08-16
@felixexter

_id: 53e91147ce282615c3f61423,

The value must be in quotes.
_id: '53e91147ce282615c3f61423',

P
pomeo, 2014-08-18
@pomeo

verse['genre_id']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question