【发布时间】:2022-04-05 01:18:22
【问题描述】:
我正在练习关于 Jade 模板和 expressjs 的hackerrank 问题。 文件如下。 app.js
// set 'jade' as the 'view engine'
// render the jade template engine with the following data as parameter:
// option:"teachers" / "students",
// Students:["A", "B", "C", "D", "E"],
// Teachers :["AB", "BC", "CD", "DE"]
// run the application on port 8000
const express= require('express');
var app = express();
app.set('views', __dirname + '/views');
app.set("view engine","jade")
app.get('/',(req,res)=>{
res.render('index', {
option:'students' || 'teachers',
Students:["A", "B", "C", "D", "E"],
Teachers :["AB", "BC", "CD", "DE"]
});
})
app.listen(8000)
index.jade
html
title Jade Template Engine
body
h1 Conditions and Loops in Jade
if option==="students"
ol
each name in Students
li #{name}
else if (option === "teachers" )
ol
each name in Teachers
li #{name}
else
p You have entered wrong option!
我如何发送 "students" 或 "teachers" 但不能同时作为参数从 app 发送到 option 变量。 js 到 index.jade
【问题讨论】: