S
S
sid3r2015-04-21 17:27:06
Node.js
sid3r, 2015-04-21 17:27:06

How to display data from the server (node,jade)?

Good day!
I will warn you in advance that I am new to JS and everything related to it.
A little about where everything happens and what is used.
node.js/express/jade/postgresql
I get data from server like this:

var query = connection.query('SELECT * FROM table');
    query.on('row', function(row, result) {
      result.addRow(row);
    });
    query.on('end', function(result) {
      data = result.rows;
      console.log(data);
    });

Conclusion:
[ { id: 1,
    name: "Pinky",
    text: "Little story about Pinky" },
 { id: 2,
    name: "Brain",
    text: "They'll take over the world" } ]

Or in JSON
-
So this data needs to be displayed on the page (dynamically), and the question is - how to do it?
I use for jade to generate pages.
I know about simple jade iterations, jade-lang.com/reference/iteration , but I don’t know exactly how to do what I described above .. well, I also learned how to simply send a variable and display it on the page.
ps if you have advice on how to organize this kind of process in a different way, please also write.
Thank you very much!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sid3r, 2015-04-21
@sid3r

I figured it out myself, sighing and watching how answers to related topics appear ..
data:

[ { id: 1,
    name: "Pinky",
    text: "Little story about Pinky" },
 { id: 2,
    name: "Brain",
    text: "They'll take over the world" } ]

On the server:
In jade:
each page in pages
 p
  h1= page.name
  a= page.text
  hr

Displays 2 paragraphs with submitted content

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question