JTemplate学习(一)
使用模板绑定数据,可以嵌套循环
参考:http://www.doc88.com/p-6621237324128.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!-- saved from url=(0043)http://jtemplates.tpython.com/example1.html -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="Scripts/jTemplates/example/jquery.js"></script>
<script type="text/javascript" src="Scripts/jTemplates/jquery-jtemplates.js"></script>
<title>jTemplates</title>
<script type="text/javascript"> $(document).ready(function () {
//测试数据 JsonData,其中含有嵌套集合,可以双层循环
var data = {
name: 'User list',
list_id: 4,
table: [
{ id: 1, name: 'Anne', age: 22, mail: 'anne@domain.com', childs: [{ name: "k1", age: "5" }, { name: "k2", age: "3" }, { name: "k2", age: "3" }, { name: "k2", age: "3" }] },
{ id: 2, name: 'Amelie', age: 24, mail: 'amelie@domain.com' },
{ id: 3, name: 'Polly', age: 18, mail: 'polly@domain.com' },
{ id: 4, name: 'Alice', age: 26, mail: 'alice@domain.com' },
{ id: 5, name: 'Martha', age: 25, mail: 'martha@domain.com' }
]
}; // 附加模板,模板id:template
$("#result1").setTemplateElement("template"); // 处理模板,填充数据
$("#result1").processTemplate(data); //setTemplateElement 指定可处理的模板对象
//processTemplate 对模板化的对象进行数据处理
//$T 为模板提供数据调用功能
//$P 为模板提供参数变量调用功能
//$Q.version 提供当前JTemplate的版本信息 //{#if $T.list_id == 3}System List{#elseif $T.list_id == 4}User List{#else}Error List{#/if} //if else 判断 //{#foreach $T.table as record}{$T.record.name}{#/for} //循环
//{#foreach $T.table as record begin=1}{$T.record.name}{#/for} //指定起始位置
//{#foreach $T.table as record count=2}{$T.record.name}{#/for} //指定循环次数
//{#foreach $T.table as record step=2}{$T.record.name}{#/for} //指定步长 //{$T.record$index} 编号,从0开始
//{ $T.record$iteration } 下标,从0开始
//{ $T.record$first } 是否是第一个元素:true/false
//{ $T.record$last } 是否是最后一个元素:true/false
//{ $T.record$total } 总记录数
//{ $T.record$key } 数据的键值
//{ $T.record$typeof } 数据类型 //{#break} {#continue} 跳出循环、结束此次,继续下一次循环 //支持循环集合用函数代替
//$("#result1").setTemplate("{#foreach fc as fcValue begin=10 end=40}{$T.fcValue}<br />{#/for}");
//$("#result1").processTemplate(); //for循环
//{#for index=1 to 10 }{$T.index}{#/for}
//{#for index=1 to 10 step=3}{$T.index}{#/for} //正向步长
//{#for index=1 to 10 step=-3}{$T.index}{#else}nothing{#/for} //负向步长,空循环,输出nothing
//{#for index=10 to 0 step=-3}{$T.index}{#else}nothing{#/for} //负向步长,输出10 7 4 1
//{#for index=$T.start to $T.end}{$T.index}{#/for} //循环中使用变量
}); //支持循环集合用函数代替
//var fc = function (step) {
// if (step>30) {
// return null;
// }
// return "step:" + step;
//}
</script> <style type="text/css">
.jTemplatesTest {
background: #DDD;
border: 1px solid #000;
margin: 2em;
width: 480px;
} .jTemplatesTest * {
padding: 4px;
margin: 2px auto;
} .jTemplatesTest td, tr {
background: #EEE;
border: 1px solid black;
}
</style>
</head> <body style="zoom: 1;"> <!-- 模板内容 开始 -->
<textarea id="template" style="display: none">
<strong>{$T.name}: {$T.list_id}</strong>
<table>
{#foreach $T.table as record}
<tr>
<td>{$T.record$index+1}</td>
<td>{$T.record.id}</td>
<td>{$T.record.name}</td>
<td>{$T.record.age}</td>
<td>{$T.record.mail}</td>
</tr>
<tr>
<td colspan="5">Childs</td>
</tr>
{#foreach $T.record.childs as ch}
<tr>
<td></td>
<td></td>
<td>{$T.ch$index+1}</td>
<td>{$T.ch.name}</td>
<td>{$T.ch.age}</td>
</tr>
{#/for}
{#/for}
</table>
</textarea>
<!-- 模板内容 结束 --> <!-- 输出数据 开始 -->
<div id="result1" class="jTemplatesTest">
</div>
<!-- 输出数据 结束 --> <!--JTemplate 官网:http://jtemplates.tpython.com/-->
</body>
</html>
JTemplate学习(一)的更多相关文章
- JTemplate学习(四)
注释.自定方法.模板嵌套子模板.循环输出不同class <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "htt ...
- JTemplate学习(三)
另一种模板写法 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xh ...
- JTemplate学习(二)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DT ...
- 从直播编程到直播教育:LiveEdu.tv开启多元化的在线学习直播时代
2015年9月,一个叫Livecoding.tv的网站在互联网上引起了编程界的注意.缘于Pingwest品玩的一位编辑在上网时无意中发现了这个网站,并写了一篇文章<一个比直播睡觉更奇怪的网站:直 ...
- Angular2学习笔记(1)
Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...
- ABP入门系列(1)——学习Abp框架之实操演练
作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...
- 消息队列——RabbitMQ学习笔记
消息队列--RabbitMQ学习笔记 1. 写在前面 昨天简单学习了一个消息队列项目--RabbitMQ,今天趁热打铁,将学到的东西记录下来. 学习的资料主要是官网给出的6个基本的消息发送/接收模型, ...
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- Unity3d学习 制作地形
这周学习了如何在unity中制作地形,就是在一个Terrain的对象上盖几座小山,在山底种几棵树,那就讲一下如何完成上述内容. 1.在新键得项目的游戏的Hierarchy目录中新键一个Terrain对 ...
随机推荐
- 【Codeforces】CF 2 B The least round way(dp)
题目 传送门:QWQ 分析 求结尾0的数量QwQ. 10只能是$ 2 \times 5 $,我们预处理出每个数因子中2和5的数量. 我们接着dp出从左上到右下的经过的最少的2的数量和最少的5的数量.两 ...
- linux 系统管理 实战技巧
一.这篇文章讲了什么? 这篇文章很有参考性哈.本来是想等一段时间有更多条技巧后在发布的,不过,突然发现,我是去年的今天在博客园落户了,祝我的博客一周岁快乐,希望以后多分享一些文章啦.所以就把草稿箱的其 ...
- 简单工厂法( Factory Method)
工厂方法 (Factory Method) Define an interface for creating an object ,but let subclasses decide which cl ...
- Python之模块(二)
1.subprocess模块 2.loggin模块 很多程序都有记录日志的需求,并且日志中包含的信息即有正常的程序访问日志,还可能有错误.警告等信息输出,python的logging模块提供了标准的日 ...
- vb 水晶报表打印
vb里面的水晶报表打印控件:CrystalReportViewer 用到的dll文件: 水晶报表打印其实很简单,只要创建报表对象,再对其传递数据就可以打印出来.当然所传递的数据要与水晶报表设计里面的数 ...
- 超酷的Prezi在线ppt制作网站
prezi.com 你还在用office Power Point 制作PPT吗? 使用prezi.com制作ppt试试.http://prezi.com/explore/staff-picks/
- ByteCache
private static class ByteCache { private ByteCache(){} //256个元素,用于缓存-128到127 static final Byte cache ...
- CUDA C Programming Guide 在线教程学习笔记 Part 3
▶ 表面内存使用 ● 创建 cuda 数组时使用标志 cudaArraySurfaceLoadStore 来创建表面内存,可以用表面对象(surface object)或表面引用(surface re ...
- FDMemTable 数据集
c++builder FDMemTable 内存表 内存数据表:现在应该首选 TFDMemTable 了(之前是 TClientDataSet) FDMemTable->CloneCursor( ...
- 表格(table)
Title 主机名 端口 操作 1111 10023 查看详情 修改 表头1 表头1 表头1 表头1 1 1 1 1 1 1 1 1 1 <!DOCTYPE html><html l ...