一、在jsRender中,如果想要创建一个模板,那么需要提供一个template的标记(markup),JsRender会将该标记转换或者编译成一个javascript的函数,即"render"方法。实际上,为了方便我们开发者,JsRender会为我们创建一个template对象,该对象具有一个template.render()方法。
二、有两种方式创建template。
1. 传入一个标记字符串到方法$.templates()中,该方法会将该标记字符串编译成一个template对象,并且选择性地按照该标记字符串名称注册成一个template。
2. 在一个script块中定义一个template,type为type="text/x-jsrender"。在种情况下,JsRender会自动的调用$.templates()方法。
三、相关的实例:
1. 1 根据一个标记字符串名称来创建和注册一个template(从server端获取包含有template标记的script 文件)
<div id="peopleList"></div>
$.getScript("http://www.jsviews.com/samples/resources/templates/person.js", function() { var html = $.render.person(people); $("#peopleList").html(html); }); var people = [ { name: "Adriana" }, { name: "Robert" } ];
1. 2 根据一个标记字符串名称来创建和注册一个template(从server端获取包含有template标记的text文件)
<div id="peopleList"></div>
var personTemplate; $.get("templates/person.txt", function(value) { personTemplate = $.templates(value); var html = personTemplate.render(people); $("#peopleList").html(html); }); var people = [ { name: "Adriana" }, { name: "Robert" } ];
2. 在一个script块中去注册和定义一个template
<div id="peopleList"></div> <script id="personTemplate" type="text/x-jsrender"> <label>Name:</label> {{:name}} </script>
$.templates("personTmpl", "#personTemplate"); var people = [ { name: "Adriana" }, { name: "Robert" } ]; var html = $.render.personTmpl(people); $("#peopleList").html(html);
相关推荐
NULL 博文链接:https://josh-persistence.iteye.com/blog/1914697
NULL 博文链接:https://josh-persistence.iteye.com/blog/1916759
NULL 博文链接:https://josh-persistence.iteye.com/blog/1915730
jquery 插件 高性能的js模板引擎
jquery 插件 高性能的js模板引擎,jquery-jsrender.js
jquery.fireworks.js 插件描述:jquery-fireworks.js是一款基于HTML5 Canvas的逼真烟花特效jQuery插件。该插件使用简单,并可自由进行配置。它可以在一个div容器中生成逼真的燃放...
jQuery圆角插件:jquery.corners.js
jquery.form.js jquery.form.js
jquery上传文件和参数封装的js:jquery.form.js,可用于单文件、上文件上传以及携带参数
jquery-3.0.0.js 、jquery-3.0.0.min.js 【官方jquery包 js】
jquery.cookie.js,jquery-1.11.0.min.js,respond.min.js, bootstrap.min.js,html5shiv.js
jquery.pagination.js 下载,优秀的jquery分页插件,使用IP代理国外网站下载而来
jquery.cookie.js下载 jquery.cookie.js下载
jquery.media.js
jquery.validate.js jquery.validate.js
jquery-1.11.1.js 、jquery-1.11.1.min.js 【官方jquery包 js】
jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)...
jquery-1.9.1.js 、jquery-1.9.1.min.js 【jquery包 js】
jquery-3.5.0.js jquery-3.5.0.min.js.zip
JQuery插件:alert、confirm、prompt对话框插件