我正在尝试使用ejs模板引擎建立到随机文件的链接。我在名为“ case”的文件中有一个名为randomProject的javascript字符串变量。但是,我不知道如何将这两个字符串连接在一起。
我尝试使用<a href=<% "/case/" + randomProject%>>
中的“加号”,但没有用。
index.ejs(在我想创建一个随机链接之前)
<a href='/case/portfolio-website'>
<h2>Portfolio Website</h2>
</a>
index.ejs(我想建立一个随机链接,现在不起作用了
<a href=<% "/case/" + randomProject%>>
<h2><%= randomProject %></h2>
</a>
main.js
const projects = ['gochiso','junction','portfolio-website','tedx-flyer','tedx-website','thirty-logo-challenge']
const randomNum = Math.floor(Math.random() * projects.length);
const randomProject = projects[randomNum]
目录
case
gochiso.ejs
portfolio-website.ejs
thirty-logo-challenge.ejs
junction.ejs
tedx-website.ejs
答案 0 :(得分:1)
您可以串联的两种方式:
使用 def generateBoard():
game = []
body = [1,2,3,4,5,6,7,8,9]
bodyLength = len(body)
for row in range(bodyLength):
temp = []
for col in range(bodyLength):
roll = False
## It gets a little complicated down below ##
while not roll:
sameCount = 0
a = random.choice(body)
if a not in temp:
if row != 0:
for i in range(0,row):
if a == game[i][col]:
sameCount += 1
else:
pass
else:
continue
if sameCount == 0:
temp.append(a)
roll = True
game.append(temp)
## the area above is where i am having problem in ##
return game
template literal
常规<a href="<%= `/case/${randomProject}` %>">
输出转义的html
ejs