javascript - 如何在将哈巴狗渲染成 HTML 时删除“>”
问题描述
我正在尝试制作日历。当我通过 JavaScript (Express) 将 pug 代码呈现为 HTML 时,html 代码涉及<
and >
(我什至根本没有输入),它会打印两次结果。我存储的值没有问题。我怎样才能解决这个问题?
以下是我的代码。
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;
哈巴狗:
ol.days.list-unstyled
#{addLi}
呈现的 HTML 代码:
解决方案
这很容易通过哈巴狗each
循环处理:
ol.days.list-unstyled
each item in addLi
li.date= item
只需将要显示的数字列表传递给它,然后将 HTML 生成留给 pug。
推荐阅读
- c# - 将字节写入文本文件并适当地读取它们
- javascript - 如何将对象名称添加到数组javascript中
- sql - 我们如何根据SQL从前一列的数量计算出的比率来计算值?
- assembly - 关于编写可执行文件打包器的两个问题
- javascript - 画布中的动画剪贴蒙版
- java - Spring JDBC tomcat 资源被锁定 - 100% CPU
- amazon-web-services - 在 aws api gateway cloudformation 中提供 vpc 端点
- android - Google Maps Android API:地图样式解析失败:设置地图样式时为空
- flask - swagger 中用于分组方法的 flask-api-spec 标签
- c++ - 运算符重载声明中的第一个参数是什么意思?