1.这个插件挺好用的,可以用它来代替微软的gridview,前提是您用了asp.net mvc模式开发
下面是找到的一些英文资料,大家可以参考下

网址如下:

http://api.jquery.com/category/plugins/templates/

jQuery.tmpl( template, [data,] [options] ) Returns: jQuery

Description: Render the specified HTML content as a template, using the specified data.

  • version added: 1.4.3jQuery.tmpl( template, [data,] [options] )

    templateThe HTML markup or text to use as a template.

    dataThe data to render. This can be any JavaScript type, including Array or Object.

    optionsAn optional map of user-defined key-value pairs. Extends the tmplItem data structure, available to the template during rendering.

This documentation topic concerns the jQuery Templates plugin (jquery-tmpl), which can be downloaded from: http://github.com/jquery/jquery-tmpl.

The jQuery.tmpl() method is designed for chaining with .appendTo, .prependTo, .insertAfter or .insertBefore as in the following example.

Example:

$.tmpl( "<li>${Name}</li>", { "Name" : "John Doe" }).appendTo( "#target" );

The template parameter can be any of the following:

  • A string containing markup.
  • An HTML element (or jQuery object that wraps an element) whose content is to be used as the template.
  • A string corresponding to the name of a named template (see jQuery.template() and .template()).
  • A compiled-template function (see jQuery.template() and .template()).

If data is an array, the template is rendered once for each data item in the array. If data is an object, or if the data parameter is missing or null, a single template item is rendered.

The return value is a jQuery collection of elements made up of the rendered template items (one for each data item in the array). If the template contains only one top-level element, then there will be one element for each data item in the array.

To insert the rendered template items into the HTML DOM, the returned jQuery collection should not be inserted directly into the DOM, but should be chained with .appendTo, .prependTo, .insertAfter or .insertBefore, as in following example:

$.tmpl( myTemplate, myData ).appendTo( "#target" );

See also .tmpl().

Example

The following example shows how to use jQuery.tmpl() to render local data, using a template provided as a string:

<ul id="movieList"></ul><script type="text/javascript">var movies = [{ Name: "The Red Violin", ReleaseYear: "1998" },{ Name: "Eyes Wide Shut", ReleaseYear: "1999" },{ Name: "The Inheritance", ReleaseYear: "1976" }];var markup = "<li><b>${Name}</b> (${ReleaseYear})</li>";// Compile the markup as a named template$.template( "movieTemplate", markup );// Render the template with the movies data and insert// the rendered HTML under the "movieList" element$.tmpl( "movieTemplate", movies ).appendTo( "#movieList" );
</script>

Using Remote Data

Typically the data is not local and is instead obtained using an Ajax request to a remote service or page, as in the following example:

var markup = "<li><b>${Name}</b> (${ReleaseYear})</li>";// Compile the markup as a named template
$.template( "movieTemplate", markup );$.ajax({dataType: "jsonp",url: moviesServiceUrl,jsonp: "$callback",success: showMovies
});// Within the callback, use .tmpl() to render the data.
function showMovies( data ) {// Render the template with the "movies" data and insert// the rendered HTML under the 'movieList' element$.tmpl( "movieTemplate", data ).appendTo( "#movieList" );
}

The Markup for the Template

You can get the markup for the template from inline markup in the page, or from a string (possibly computed, or obtained remotely). For an example of how to use inline markup, see .tmpl().

Caching the Template

When a template is rendered, the markup is first converted into a compiled-template function. Every time $.tmpl( markup , myData ).appendTo( "#target" ) is called, the template is recompiled. If the same template is to be used more than once for rendering data, you should ensure that the compiled template is cached. To cache the template when using markup that is obtained from a string (rather than from inline markup in the page), use $.template( name, markup ) to create a named template for reuse. See jQuery.template().

Template Tags, Expressions, and Template Variables

Template tags such as the ${} tag can used within jQuery templates in addition to text and HTML markup to enable a number of scenarios such as composition of templates, iteration over hierarchical data, parameterization of template rendering, etc. Template tags can render content based on the values of data item fields or template variables such as $item (corresponding to the template item), as well as expressions and function calls. See the documentation topics for each template tag: ${}, {{each}}, {{if}}, {{else}}, {{html}}, {{tmpl}} and {{wrap}}.

The options Parameter, and Template Items

Each template item (the result of rendering a data item with the template) is associated with a tmplItem data structure, which can be accessed using jQuery.tmplItem() and .tmplItem(), or the $item template variable. Any fields or anonomyous methods passed in with the options parameter of jQuery.tmpl() will extend the tmplItem data structure, and so be available to the template as in the following example:

var markup = "<li>Some content: ${$item.myMethod()}.<br/>" + " More content: ${$item.myValue}.</li>";// Compile the markup as a named template
$.template( "movieTemplate", markup );// Render the template with the movies data
$.tmpl( "movieTemplate", movies,{ myValue: "somevalue", myMethod: function() { return "something";} }
).appendTo( "#movieList" );

Examples:

Example: Render local data using jQuery.tmpl().

<!DOCTYPE html>
<html>
<head> <script src="http://code.jquery.com/jquery-latest.min.js"></script> <script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
</head>
<body> <ul id="movieList"></ul> <script> var movies = [ { Name: "The Red Violin", ReleaseYear: "1998" }, { Name: "Eyes Wide Shut", ReleaseYear: "1999" }, { Name: "The Inheritance", ReleaseYear: "1976" } ]; var markup = "<li><b>${Name}</b> (${ReleaseYear})</li>"; /* Compile the markup as a named template */
$.template( "movieTemplate", markup ); /* Render the template with the movies data and insert the rendered HTML under the "movieList" element */
$.tmpl( "movieTemplate", movies ) .appendTo( "#movieList" );
</script> </body>
</html>

Example: Render data from a remote service, using jQuery.tmpl().

<!DOCTYPE html>
<html>
<head> <script src="http://code.jquery.com/jquery-latest.min.js"></script> <script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
</head>
<body> <button id="cartoonsBtn">Cartoons</button>
<button id="dramaBtn">Drama</button> <ul id="movieList"></ul> <script>
var markup = "<li><b>${Name}</b> (${ReleaseYear})</li>"; /* Compile the markup as a named template */
$.template( "movieTemplate", markup ); function getMovies( genre, skip, top ) { $.ajax({ dataType: "jsonp", url: "http://odata.netflix.com/Catalog/Genres('" + genre + "')/Titles?$format=json&$skip=" + skip + "&$top=" + top, jsonp: "$callback", success: function( data ) { /* Get the movies array from the data */ var movies = data.d; /* Remove current set of movie template items */ $( "#movieList" ).empty(); /* Render the template items for each movie and insert the template items into the "movieList" */ $.tmpl( "movieTemplate", movies ) .appendTo( "#movieList" ); } });
} $( "#cartoonsBtn" ).click( function() { getMovies( "Cartoons", 0, 6 );
}); $( "#dramaBtn" ).click( function() { getMovies( "Drama", 0, 6 );
}); </script> </body>
</html>

转载于:https://www.cnblogs.com/wangzhanjianshe/archive/2011/06/21/2326426.html

jQuery.tmpl.js相关推荐

  1. jquery tmpl js 模板详解

    jquery.tmpl的几种常用标签分别有: ${}, {{each}}, {{if}}, {{else}}, {{html}} 不常用标签 {{=}},{{tmpl}} and {{wrap}}. ...

  2. Jquery 模板插件 jquery.tmpl.js 的使用方法(2):嵌套each循环,temp调用(使用预编译的模板缓存)...

    直接上代码吧 一:主窗口 /*#region SendChooseTargetTemplate 发送候选人主窗口模板*/ var SendChooseTargetTemplate = ''; Send ...

  3. 用jQuery作为JS对象从选项中添加选项的最佳方法是什么?

    使用jQuery从JavaScript对象向<select>添加选项的最佳方法是什么? 我正在寻找不需要插件的东西,但是我也对那里的插件感兴趣. 这是我所做的: selectValues ...

  4. Jquery.tmpl

    它是一个基于jquery的模板展示插件,有了它就可以去展示JSON数据渲染到HTML页中! 一.使用方法 引入Jquery 引入 tmpl <script src="../Script ...

  5. jQuery .tmpl(), .template()学习

    昨晚无意中发现一个有趣的jQuery插件.tmpl(),其文档在这里. 官方解释对该插件的说明:将匹配的第一个元素作为模板,render指定的数据,签名如下: .tmpl([data,][option ...

  6. [原]jQuery .tmpl(), .template()学习

    昨晚无意中发现一个有趣的jQuery插件.tmpl(),其文档在这里. 官方解释对该插件的说明:将匹配的第一个元素作为模板,render指定的数据,签名如下: .tmpl([data,][option ...

  7. php 掌握jquery,完全掌握jquery tmpl模板

    之前用模板渲染都是用angular,无意间发现了jquery tmpl这种轻量级,其文档在这里,本文主要为大家带来一篇jquery tmpl模板(实例讲解).小编觉得挺不错的,现在就分享给大家,也给大 ...

  8. jQuery .tmpl() 用法

    参考效果: DEMO  下载: jquery-tmpl-master 动态请求数据来更新页面是现在非常常用的方法,比如博客评论的分页动态加载,微博的滚动加载和定时请求加载等. 这些情况下,动态请求返回 ...

  9. 放弃用你的InnerHTML来输出HTML吧,jQuery Tmpl不详细讲解

    在Ajax横道的今天,我们在页面交互上有了更高的要求,动态生成HTML毫无疑问是其中的一种.动态生成HTML的方式多种多样,其核心不外乎在前段(JS)或者后端(C#/PHP-)将数据组装成我们想要的模 ...

最新文章

  1. 实习总结之jquery实例
  2. GraphPad Prism 9.3 MacOS 2021科研绘图统计 支持Monterey 安装使用教程
  3. unity 调用 .dll 或 .so时遇到的问题
  4. Jenkins的安装和卸载(转载)
  5. KVM之Live Migration
  6. selenium中Chrome和Firefox浏览器驱动的使用和版本对应
  7. [RL] pip 安装 atari-py
  8. java调用百度api完成人脸识别
  9. html5 右侧客服代码,js实现浮动在网页右侧的简洁QQ在线客服代码
  10. 微信小程序 选项卡 swiper默认高度150px(让高度实现自适应)解决方法
  11. 谁说大象不能跳舞读后感
  12. 第22批符合道路运输车辆卫星定位系统标准 及规范的车载终端
  13. Eclipse4.6(neno)配置Tomcat插件
  14. MMC子系统之SDIO卡驱动
  15. MoviePy - 中文文档4-MoviePy实战案例-追踪人脸,打马赛克
  16. 精心收集的几十个ASP编程网址
  17. 关于DefaultHttpClient的作用已经被弃之后的新方法
  18. PMP考试冲刺计算专题
  19. ug12对计算机配置要求,UG软件对电脑配置的最低要求有哪些
  20. 猿创征文|Google Earth Engine(GEE)实现土地利用数据栅格转矢量

热门文章

  1. Ubuntu12.04安装小记
  2. 设置tomcat自动启动的相关脚本
  3. MySQL5.7新特性——在线收缩undo表空间 (转载)
  4. app启动速度阶段指标
  5. Managing the Lifecycle of a Bound Service
  6. shell 数学运算
  7. 解决mxnet错误:OSError: libcudart.so.10.0: cannot open shared object file: No such file or directory
  8. 图像增强:多尺度的图像细节提升(multi-scale detail boosting)实现方法
  9. (三)通用视图(generic views)
  10. jQuery同时监听两个事件---实现同时操控两个按键