Layui__模板引擎layui.laytpl
Posted kikyoqiang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Layui__模板引擎layui.laytpl相关的知识,希望对你有一定的参考价值。
layui.laytpl快速使用
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link href="../lib/layui/css/layui.css" rel="stylesheet" />
</head>
<body>
<div id="view"></div>
<script src="../lib/layui/layui.js"></script>
<script id="demo" type="text/html">
<h3>{{ d.title }}</h3>
<ul>
{{# layui.each(d.list, function(index, item){ }}
<li>
<span>{{ item.modname }}</span>
<span>{{ item.alias }}:</span>
<span>{{ item.site || ‘‘ }}</span>
</li>
{{# }); }}
{{# if(d.list.length === 0){ }}
无数据
{{# } }}
</ul>
</script>
<script>
var data = { //数据
"title": "Layui常用模块"
, "list": [{ "modname": "弹层", "alias": "layer", "site": "layer.layui.com" }, { "modname": "表单", "alias": "form" }]
}
layui.use(‘laytpl‘, function () {
var laytpl = layui.laytpl;
var getTpl = demo.innerHTML
, view = document.getElementById(‘view‘);
laytpl(getTpl).render(data, function (html) {
view.innerHTML = html;
});
});
</script>
</body>
</html>
以上是关于Layui__模板引擎layui.laytpl的主要内容,如果未能解决你的问题,请参考以下文章