如何每隔5分钟左右用不同的渲染参数自动进行页面渲染?是否可以使我坐在索引页上,并且指定的字段将按指定的时间间隔进行更新?
当前,我仅通过使用不同的路由“ /”和“实验室”并手动访问它们来显示该信息。我尝试使用每个GET更改的数据在uniTimes [0] .lectures和uniTimes [1] .labs之间,并且在每次渲染时,我都在blockHeights和verticalPosition变量中更改数据。
获取指向索引页面的请求:
router.get('/', function(req, res, next) {
// Lectures/Lab Works times object array
var uniTimes = [
{
lectures: [
{
title: "Information System Security",
classroom: "503a.",
start: "1995-12-17T08:00:00",
end: "1995-12-17T09:15:00"
},
{
title: "Project Management",
classroom: "117a.",
start: "1995-12-17T08:30:00",
end: "1995-12-17T09:30:00"
},
{
title: "Audiovisual Art",
classroom: "228a.",
start: "1995-12-17T09:45:00",
end: "1995-12-17T12:00:00"
}
]
},
{
labs: [
{
title: "Graphic Design",
classroom: "505a.",
start: "1995-12-17T09:15:00",
end: "1995-12-17T10:15:00"
},
{
title: "Special Effects",
classroom: "228a.",
start: "1995-12-17T11:30:00",
end: "1995-12-17T12:00:00"
},
{
title: "Robotics",
classroom: "513a.",
start: "1995-12-17T08:45:00",
end: "1995-12-17T09:30:00"
}
]
}
]
//Displayed lecture/lab work block size
var blockHeights = ["250px", "200px", "450px"];
//Displayed lecture/lab work block position
var verticalPosition = ["0px", "100px", "350px"];
res.render('index', { title: 'Express Application', subTitle: 'Student Timetables Display', uniTimes: uniTimes[0].lectures, blockHeights: blockHeights, verticalPosition: verticalPosition });
});
索引Ejs页面:
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<h1><%= title %></h1>
<p>Welcome to <%= subTitle %></p>
<a href="/admin">Go to admin panel</a>
<br>
<br>
<% for(var i = 0; i < uniTimes.length; i++) { %>
<div style="float:left; width: 150px; margin-right: 25px; height: <%= blockHeights[i] %>; background-color: red; margin-top: <%= verticalPosition[i] %>">
<h3><%= uniTimes[i].title %></h3>
<h4><%= uniTimes[i].classroom %></h4>
<h4><%= uniTimes[i].start %></h4>
<h4><%= uniTimes[i].end %></h4>
</div>
<% } %>
</body>
</html>