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对 ...
随机推荐
- sklearn安装
1.准备工作 安装sklearn之前,我们需要先安装numpy,scipy函数库. 由于用pip install numpy, scipy大概率安装失败(Win下),一个简单的解决方法是安装UCI第三 ...
- css 元素选择器实例
一个完整的HTML页面是有很多不同的标签组成,而标签选择器,则是决定哪些标签采用相应的CSS样式.本文章向码农介绍css 标签/元素选择器以及其实例,需要的码农可以参考一下. [标签选择器] 一个完整 ...
- tensorflow data's save and load
note: if you'll load data,the data shape should be similar with saved data's shape. -- 中式英语,天下无敌 ...
- MPP、SMP、NUMA概念介绍
一.MPP,SMP,NUMA概念介绍 1.1. MPP架构介绍 MPP (Massively Parallel Processing),大规模并行处理系统,这样的系统是由许多松耦合的处理单 ...
- SQL语言类别
SQL语言主要分为四大类:数据查询语言DQL,数据操纵语言DML, 数据定义语言DDL,数据控制语言DCL. DQL (data query language) DML(data manipulati ...
- How to Pronounce EVERY
How to Pronounce EVERY Share Tweet Share Tagged With: 2-Syllable Everybody should learn the word ‘ev ...
- 英语广播原声听力100篇MP3及听力原文
=============7.6================ Passage 031- 人工智能对人类的利与弊From a personal assistant, to doing searche ...
- ndarray
ndarray ndarray-多维数组对象 ndarray数组分两部分 实际数据 描述数据的元数据(数据类型/维度等) ndarray所有元素类型相同,下标从0开始 import numpy as ...
- kegg富集分析之:KEGGREST包(9大功能)
这个包依赖极有可能是这个:https://www.kegg.jp/kegg/docs/keggapi.html ,如果可以看懂会很好理解 由于KEGG数据库分享数据的策略改变,因此KEGG.db包不在 ...
- spring-boot PageHelper
分页插件PageHelper 参看了pagehelper-spring-boot,使用起来非常放方便,关于更多PageHelper可以点击https://github.com/pagehelper/M ...