[英]how to remove ">" when render pug into HTML
I'm trying to make a calendar.我正在尝试制作日历。 When I rendered a pug code into HTML by JavaScript (Express), the html code involves <
and >
(which I didn't even typed at all) and it prints the result twice.当我通过 JavaScript (Express) 将 pug 代码渲染为 HTML 时,html 代码涉及<
和>
(我什至没有输入)并且它会打印两次结果。 there were no problem with the value I stored.我存储的值没有问题。 how can I fix this?我怎样才能解决这个问题?
Following is my code.以下是我的代码。
JavaScript: JavaScript:
var express = require('express');
var router = express.Router();
var moment = require('moment');
require('moment-timezone');
moment.tz.setDefault("Asia/Seoul");
//get the day of the first date of month
function getDay() {
var date = new Date();
var day = date.getDay();
var _date = date.getDate();
var firstDay = day - ((_date % 7) - 1);
var month = date.getMonth();
var dayPMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var curMonth = dayPMonth[month];
var year = date.getFullYear();
var output = '';
if(firstDay < 0) {
firstDay = firstDay + 7;
}
for(var i = 0; i <= firstDay; i++) {
output = output + '<li></li> '
}
if(month === 1) {
if(year % 400 === 0) {
curMonth++;
}
else if(year % 100 !== 0 && year % 4 === 0) {
curMonth++;
}
}
for(var i = 1; i <= curMonth; i++) {
output = output + "<li class = \"date\">"+i;
output = output + "</li> "
}
return output;
}
router.get('/', function(req, res, next) {
var li = '';
li = getDay();
console.log(li);
res.render('main', { title: 'ALMANAC', headerNum : 3, nickname : 'userId', notice: 'none', trophy : 0, money : 0, addLi : li});
});
module.exports = router;
Pug:帕格:
ol.days.list-unstyled
#{addLi}
Rendered HTML code:渲染的 HTML 代码:
This is easily handled by a pug each
loop:这很容易由哈巴狗each
循环处理:
ol.days.list-unstyled
each item in addLi
li.date= item
Just pass it the list of numbers you want displayed, and leave the HTML generation to pug.只需将您要显示的数字列表传递给它,然后将 HTML 生成留给 pug。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.