backend code
data contains the result of the query, which is an array of objects
res.render ("search_result", {title:" query result page", data: result});
Front end code
the jade template engine is not used here, so the way to get it is <% >
of HTML.var data = "<% = JSON.stringify (data)% >";
alert (data);
then the result is.
as shown in the figure, the obvious passed object array is parsed as a string, and all symbols in it are also integrated into escape characters
.personal needs
as mentioned above, the personal requirement is to send the page and hand in the queried data at the same time, and then render dynamically. Therefore:
- if there is a more elegant solution that can meet the above requirements, I would appreciate your advice;
- I would also appreciate it if I could solve the above problem of passing an array of objects.
in addition, I am a Node rookie. I have only been self-taught for less than two months, and I have not finished my express documents yet, so I hope to give a relatively detailed solution. Thank you
.