轻量的前端渲染模板JsRender
JsRender,Best-of-breed templating Simple and intuitive, powerful and extensible, lightning fast.
简单易用,上手快!提升前端开发效率。
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://www.jsviews.com/download/jsrender.min.js"></script>
<link href="https://www.jsviews.com/samples/samples.css" rel="stylesheet" />
</head>
<body>
<div id="result"></div>
<script id="theTmpl" type="text/x-jsrender">
<div>
<em>Name:</em> {{:name}}
{{if showNickname && nickname}}
(Goes by <em>{{:nickname}}</em>)
{{/if}}
</div>
</script>
<script>
var data = [
{
"name": "Robert",
"nickname": "Bob",
"showNickname": true
},
{
"name": "Susan",
"nickname": "Sue",
"showNickname": false
}
];
var template = $.templates("#theTmpl");
var htmlOutput = template.render(data);
$("#result").html(htmlOutput);
</script>
</body>
</html>
运行结果(对模板中的内容进行渲染)
Name: Robert (Goes by Bob)
Name: Susan
本文为原创文章,想了解更多信息欢迎访问我的博客
https://www.cnblogs.com/ihappycat/