如何显示MySQL的“结果"反对用快速把手的用户? [英] How to display MySQL "result" object to user with express-handlebars?
本文介绍了如何显示MySQL的“结果"反对用快速把手的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前在节点js中有一个查询,如下所示:
I currently have a query in my node js that looks like this:
app.get('/fav/books', function(req, res){
var sql = ("SELECT title, pictureUrl, author, description, genre FROM books")
connection.query(sql, function(err, result){
if(err) {
console.log('Error in the query.');
} else {
console.log('Success!\n');
console.log(result);
var book = result;
return book;
}
});
});
并输出到控制台,如下所示: 控制台输出
And outputs to console like this: Console Output
我想还书";在这样的卡片输出中通过把手提供给用户:
I want to "return book;" to the user with handlebars in a sort of card output like this:
<div class="page-carousel">
<div class="panel id1">
<img href="pictureUrl"/>
<h3>title</h3>
<p><strong>author</strong></p>
<p>description</p>
<p>genre</p>
</div>
</div>
该面板将是Book的ID,因为它需要创建与ID一样多的面板.图书信息将保持不变.
The panel would be the ID of the Book as it needs to create as many panels as there are IDs. The book information would be as is.
推荐答案
Angularjs就是完美的选择.将此响应对象分配给一个$ scope变量,例如$ books.然后您可以执行以下操作:
Angularjs is just perfect for this. Assign this response object to a $scope variable say $books.Then you could do this:
<div class="page-carousel">
<div ng-repeat="x in books" class="panel {{x.id}}">
<img href="{{x.pictureUrl}}"/>
<h3>{{x.title}}</h3>
<p><strong>{{x.author}}</strong></p>
<p>{{x.description}}</p>
<p>{{x.genre}}</p>
</div>
</div>
这篇关于如何显示MySQL的“结果"反对用快速把手的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文