如何解决使用PostgreSQL在换行符/空格上以数据类型文本显示数据
在Postgresql中,成分和方向的数据类型设置为文本。当我在如下所示的postgre中的可编辑字段中输入数据时,它们不会在网页上以换行符显示。如果我再添加一个空白行,它也不会反映在网站上,则同样适用。我尝试在可编辑字段中的单词末尾输入“ \ n”,但这不起作用。
Postgre查看数据:
SELECT * FROM public.recipes
ORDER BY id ASC
Postgre可编辑字段:
eggs
milk
sugar
chocolate
unsalted butter
站点:
eggs milk sugar chocolate unsalted butter
Postgre可编辑的字段说明:
1. this is a test
2. this is another test
3. and another test
站点:
1. this is a test 2. this is another 3. test and another test
app.js
app.get('/',function(req,res) {
var pool = new pg.Pool(config)
// PG connect
pool.connect(function(err,client,done) {
if(err) {
return console.error('Error fetching client from pool',err);
}
client.query('SELECT * FROM recipes',function(err,result) {
if(err) {
return console.error('Error running query',err);
}
res.render('index',{recipes: result.rows});
done();
});
});
});
layout.dust
<!DOCTYPE html>
<html>
<head>
<title>Recipes</title>
<link rel="stylesheet" href="/stylesheets/bootstrap.css">
<link rel="stylesheet" href="/stylesheets/style.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-offset-2 col-md-7">
{+body /}
</div>
</div>
{+modals /}
</div>
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
<script src="/javascripts/bootstrap.js"></script>
<script src="/javascripts/main.js"></script>
</body>
</html>
index.dust
{>"layout" /}
{<body}
{#recipes}
<div class="well">
<h4>{name}
<button class="btn btn-default pull-right" type="button" data-toggle="collapse" href="#recipe_{id}" aria-expanded="false" aria-controls="recipe_{id}">
<span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
</button></h4>
<div class="collapse" id="recipe_{id}">
<p><strong>Ingredients: </strong>{ingredients}</p>
<p><strong>Directions: </strong>{directions}</p>
</div>
</div>
{/recipes}
{/body}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。