我目前正在將 node/express 應用程式從 mongodb 設定移動到 postgres 設定。我有一個頁面(report.ejs),它顯示了一個專案表以及它們是“真”還是“假”。但是,報告似乎沒有顯示這些“真”或“假”值,盡管當我在 SQL Shell 中訪問表時它們已成功保存在資料庫中。
這是 div 結構的示例。pipeline.url并pipeline.score成功顯示在網頁上,但是pipeline.firstItem,pipeline.secondItem所有其他專案均未顯示在表格中。
report.ejs 示例代碼:
<div id="main_content_wrap" class="outer">
<section id="main_content" class="inner">
<div class="container">
<h1 class="mb-1" id="reportURL"><%= pipeline.url %></h1>
<div class="text-muted mb-2" id="reportDate">
<%= pipeline.createdAt %>
</div>
<div class="text-muted mb-2">
Score Succesfully Saved
</div>
<div class="text-muted mb-2">
<%= pipeline.score %>
</div>
<table id="upcReport">
<tr>
<th>Items</th>
<th>Implemented</th>
</tr>
<tr>
<th>Header 1</th>
<th></th>
</tr>
<tr>
<td>This is the first item</td>
<td><%= pipeline.firstItem %></td>
</tr>
<tr>
<td>This is the second item</td>
<td><%= pipeline.secondItem %></td>
</tr>
</table>
<button onclick="exportData()">Download Report</button><br>
<a href="/" class="btn btn-secondary">Home</a>
<a href="/pipelines/edit/<%= pipeline.id %>" class="btn btn-info">Edit</a>
</div>
</section>
</div>
盡管表中的每個專案都已設定了VARCHAR(100)資料型別,但這是事實。我嘗試使用BOOLEAN和TEXT資料型別,但問題仍然存在。
Table creation smaple from server.js
const sql_create_pipeline = `CREATE TABLE IF NOT EXISTS Pipelines (
pipeline_id SERIAL PRIMARY KEY,
slug VARCHAR(100) NOT NULL,
gear VARCHAR(100) NOT NULL,
app VARCHAR(100) NOT NULL,
url VARCHAR(100) NOT NULL,
score VARCHAR(100) NOT NULL,
createdAt VARCHAR(100),
firstItem VARCHAR(100) NOT NULL,
secondItem VARCHAR(100) NOT NULL,
);`;
uj5u.com熱心網友回復:
正如上面評論中提到的,問題只是我在pipeline.firstItemand中有大寫字符pipeline.secondItem。將它們更改為pipeline.firstitem并pipeline.seconditem解決了問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/448865.html
標籤:node.js postgresql rest express ejs
上一篇:無法使用和連接到MongoDB
