不确定我在这里做错了什么..
questions.js
questions = [];
questions.AA = 'First'
questions.BB = 'Second'
questions.CC = 'Third'
res.render('questions', { title: questions[CC], questions: questions });
questions.jade
extends layout
block content
h1= title
p #{questions.CC}
each question in questions
p= question
呈现
<body>
<h1>Third</h1>
<p>Third</p>
</body>
所以
each question in questions
p= question
似乎没有像我期望的那样工作。我错过了什么?
答案 0 :(得分:1)
您创建了一个数组,然后将值存储到字母索引而不是整数索引中。因此,each
不会循环遍历它们。你可能想要像这样定义questions
:
questions = []
questions[0] = 'First'
questions[1] = 'Second'
questions[2] = 'Third'
或者,更具惯用性:
questions = [
'First',
'Second',
'Third'
]
你必须找出一些东西来取代你获得title
的方式,但这应该可以解决这个问题。