当前位置:网站首页>art-template模板引擎过滤器的使用【入门简单使用篇】
art-template模板引擎过滤器的使用【入门简单使用篇】
2022-07-30 05:40:00 【星月前端】
1.注册过滤器
template.defaults.imports.dateFormat = function(date, format){/*[code..]*/}; template.defaults.imports.timestamp = function(value){return value * 1000};
过滤器函数第一个参数接受目标值。
2.标准语法
{ {date | timestamp | dateFormat 'yyyy-MM-dd hh:mm:ss'}}
{ {value | filter}}
过滤器语法类似管道操作符,它的上一个输出作为下一个输入。
代码演示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./template-web.js"></script>
</head>
<body>
<script id="temp" type="text/html">
<div>我是名字叫{
{name}}</div>
<div>我今年{
{age}}岁</div>
<!-- 标准语法-过滤器 -->
<h3>{
{regTime | dateFormat}}</h3>
</script>
<script>
// 定义一个dateFormat的过滤器,过滤时间
template.defaults.imports.dateFormat = function(data) {
console.log(data);
var y = data.getFullYear()
var m = data.getMonth() + 1
var d = data.getDate()
return y + '-' + m + '-' + d
}
var obj = {
name: '星月',
age: 22,
regTime: new Date() //new一个时间
}
var res = template('temp', obj)
document.write(res) //写到页面
</script>
</body>
</html>
边栏推荐
- How is crawler data collected and organized?
- 5.5线程池
- Summary of SQL classic interview questions in 2022 (with analysis)
- ezTrack-master使用教程
- Different usage scenarios of subqueries as retrieval tables and the question of whether to add aliases
- Record Breaker (Google Kickstart2020 Round D Problem A)
- 4461. Range Partition (Google Kickstart2022 Round C Problem B)
- navicat新建数据库
- 665.非递减数列
- np.where()用法
猜你喜欢
‘kaggle视频游戏销售数据的可视化和分析‘项目实现
flask-socketio实现的网页聊天室(二)
torch.load()
cnpm installation steps
Navicat cannot connect to mysql super detailed processing method
0基础玩转C语言—初识C语言(上)
2022 SQL big factory high-frequency practical interview questions (detailed analysis)
数据操作 / 数据预处理
Navicat new database
MySql fuzzy query Daquan
随机推荐
I/O多路复用技术
torch.optim.Adam()
384.打乱数组
This dependency was not found:
安装pytorch
瑞吉外卖项目:新增菜品与菜品分页查询
Basic syntax of MySQL DDL and DML and DQL
flask的笔记
131.分割回文串
秒杀项目的总结及面试常见问题
It is enough for MySQL to have this article (37k words, just like Bojun!!!)
字符串(一) 哈希
EOF的用法——while(scanf(“%d“,&num)!=EOF)
C语言(入门篇一)
Navicat new database
646.最长数对链(动态规划)
net start mysql MySQL service is starting. MySQL service failed to start.The service did not report any errors.
Qt实现单击或双击QTableWidge/View表头进行排序
np.argsort()函数详细解析
2022 SQL big factory high-frequency practical interview questions (detailed analysis)