[英]Interating through imported json in node.js and express, then displaying with jade
[英]Displaying variables from Node.js Express app in Jade filej
我有一個非常簡單的翡翠頁面,它無法正確顯示從javascript路由傳入的所有變量。 我已經嘗試過此答案中描述的方法,但在我的情況下不起作用。 我只是試圖顯示3個變量:頁面標題和兩個按鈕文本。
到目前為止,僅標題可以正確顯示,而按鈕文本則完全不顯示。
這是routes/index.js
的代碼
/* GET home page. */
router.get('/', function(req, res, next) {
res.render(
'index',
{locals:{
title: 'Real-Time Music Collaborator',
buttonText1: 'Login',
buttonText2: 'Start Creating',
}}
);
});
這是views/layout.jade
的代碼
doctype html
html.full-screen
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body.full-screen
block content
這是views/index.jade
的代碼
extends layout
block content
div.base-background-colour.no-margin.height-20.padding-100
h1.centre-text.dark-grey-colour.no-margin= title
button
h3.centre-text.dark-grey-colour= buttonText1
button
h3.centre-text.dark-grey-colour= buttonText2
令我感到困惑的是,即使我將title
變量更改為use =
pre-append,但title
變量如何正常工作,但是無論我為它永遠不會顯示的兩個按鈕文本嘗試什么。 在呈現的html中,按鈕文本不存在,因此這不是由類引起的樣式問題。
如果有幫助,我正在運行Express 4.14.0
版本。 謝謝!
不要在locals
定義對象。 只需通過一個匿名對象,例如
app.get('/', function(req, res) {
res.render('index', {
var1: 'myVariable'
})
})
然后刪除locals
定義,例如p #{myVariable}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.