<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Sales</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery-jtemplates.js"></script>
<link rel="stylesheet" href="style.css">
<script type="text/javascript">
<!--
//global variables
Items = null;
Customers = null;
Sales = null;
//update selection of Customers and refresh entries
function UpdateCustomer(elem, index) {
Customers[index].selected = elem.checked;
UpdatEntries();
}
//update selection of Items and refresh entries
function UpdateItem(elem, index) {
Items[index].selected = elem.checked;
UpdatEntries();
}
//refresh entries
function UpdatEntries() {
//local key cache
var CustCacheMap = {};
var ItemCacheMap = {};
//build key cache
for(var i=0; i<Customers.length; ++i) {
CustCacheMap[Customers[i].ID] = Customers[i];
}
for(var i=0; i<Items.length; ++i) {
ItemCacheMap[Items[i].ID] = Items[i];
}
//create resultset from all Sales entries
var entries = $.map(Sales, function(e) {
//find customer and item
var cust = CustCacheMap[e.CustomerID];
var item = ItemCacheMap[e.ItemID];
//if customer of item not found skip record
if(cust == null || item == null) {
return null;
}
//if both customer and item are selected then put record
if(cust.selected && item.selected) {
return [{
"CustName": cust.FirstName + ' ' + cust.LastName,
"ItemName": item.Name,
"Price": e.SalesPrice,
"Cost": e.UnitCost
}];
} else {
return null;
}
});
//process template
$("#Entries").processTemplate(entries);
}
$(document).ready(function() {
//load data
$.getJSON('data.json', function(data) {
Items = data.Items;
Customers = data.Customers;
Sales = data.SalesEntry;
//setup templates
$("#Customers").setTemplateElement("Template-ListCustomers").processTemplate(Customers);
$("#Items").setTemplateElement("Template-ListItems").processTemplate(Items);
$("#Entries").setTemplateElement("Template-Entries");
$("#Entries").processTemplate(null); //process empty data to show header
});
});
-->
</script>
</head>
<body>
<!-- Templates -->
<p style="display:none"><textarea id="Template-ListCustomers" rows="0" cols="0"><!--
<div class="title">Customers</div>
<table>
<tr>
<td class="header">Choose</td>
<td class="header">Name</td>
</tr>
{#foreach $T as Row}
<tr class="{#cycle values=['bcEED','bcDEE']}">
<td><input type="checkbox" value="{$T.Row.ID}" onclick="UpdateCustomer(this,{$T.Row$index})") /></td>
<td>{$T.Row.FirstName} {$T.Row.LastName}</td>
</tr>
{#/for}
</table>
--></textarea></p>
<p style="display:none"><textarea id="Template-ListItems" rows="0" cols="0"><!--
<div class="title">Items</div>
<table>
<tr>
<td class="header">Choose</td>
<td class="header">Name</td>
</tr>
{#foreach $T as Row}
<tr class="{#cycle values=['bcEED','bcDEE']}">
<td><input type="checkbox" value="{$T.Row.ID}" onclick="UpdateItem(this,{$T.Row$index})") /></td>
<td>{$T.Row.Name}</td>
</tr>
{#/for}
</table>
--></textarea></p>
<p style="display:none"><textarea id="Template-Entries" rows="0" cols="0"><!--
<div class="title">Entries</div>
<table>
<tr>
<td class="header">Customer</td>
<td class="header">Item</td>
<td class="header">Price</td>
<td class="header">Cost</td>
<td class="header">Profit</td>
</tr>
{#param name=ProfitTotal value=0}
{#foreach $T as Row}
<tr class="{#cycle values=['bcEED','bcDEE']}">
<td>{$T.Row.CustName}</td>
<td>{$T.Row.ItemName}</td>
<td>{$T.Row.Price}</td>
<td>{$T.Row.Cost}</td>
<td>{$T.Row.Price - $T.Row.Cost}</td>
</tr>
{#param name=ProfitTotal value=$P.ProfitTotal + ($T.Row.Price - $T.Row.Cost)}
{#/for}
<tr>
<td class="header"></td>
<td class="header"></td>
<td class="header"></td>
<td class="header">Total:</td>
<td class="header">{$P.ProfitTotal}</td>
</tr>
</table>
--></textarea></p>
<!-- Output elements -->
<div id="Customers" class="Content"></div>
<div id="Items" class="Content"></div>
<div id="Entries" class="Content"></div>
</body>
</html>
分享到:
相关推荐
jtemplate+jquery 做的简单的例子,在开发中用前台js模板技术,在开发中 处理 json显示模板技术
支持80和2000数据shp到txt互相转换,支持省级和部级格式。
JQuery1.3.2、1.4.1的min和vsdoc文件,附加jtemplate
JTemplate为cli,awt,swing,swing-mdi,applet和servlet应用程序生成Java源代码。 用户仅输入一些参数(类名,包名,...),JTemplate将创建所有必需的文件。
本示例简单实现网络的三层架构,利用ado将数据从数据库中获取,再利用jTemplate.js实现的方法,配合Jquery将数据绑定到页面上,例子很简单,有问题望大家指正,互相交流!
结合网上的示例,做的ajax分页代码示例,但实现并非是自己写分页对象什么的,而是用SQL语句根据页号选择查找。
jtemplate是一个基于JQuery的模板引擎插件,功能非常强大,有了她你就再不用为使用JS绑定数据集而发愁了。 主要思路,复制textarea作为模板,ajax加载json数据,添加模板,绑定数据,更新加载更多事件。 //加载更...
JTemplate插件 该插件可帮助您将变量填充到模板文件中。 它最初旨在在HTML文件中填充自定义标签。 但是,由于它不依赖于HTML处理例程,因此可以在任何上下文中使用。 换句话说,如果您有一个字母和字母的模型,喜欢...
[WebMethod] public string GetData(string currIndex, string pageSize) { string data = string.Empty; int pageCount = -1; List<Item> itemList = new List(); for(int i=0;... itemList.Add(new Item() { ...
jquery,jtemplates 实例,有3个DEMO
jTemplates是一套用作较广的基于jQuery开发的javascript模板引擎,用它可以配合ASP/PHP/JSP/等众多语言来完成诸如通过JavaScript获取JSON数据、获取一个HTML模板、构建客户端分页表格、与数据结合生成HTML静态页面的...
Node-Neo4j模板 这是一个模板 + 应用程序,使用库(在npm上可作为neo4j )。 演示在Heroku上的上运行。 该应用程序是一个简单的社交网络管理器:它使您可以添加,删除,关注和取消关注用户。 它是基本的,UI很糟糕...
neo4j_example_1 这是neo4j数据库示例。 neo4j是表数据库,它是非关系型
用于web开发中前端数据绑定。jtemplate是在jquery的基础上实现的,所以脚本的引入顺序不能颠倒,否则会报错。
☆☆ 资源说明:☆☆ ☆ 设计模式 ☆ Periodic Refresh and Timeout Pattern; Client-side data binding with jTemplate; Unique URL Pattern; Predictive Fetch Pattern;
Jtemplate基本依赖;包含commons-logging-1.2.jar,spring-beans-5.0.0.RELEASE.jar,spring-core-5.0.0.RELEASE.jar,spring-jdbc-5.0.0.RELEASE.jar,spring-tx-5.0.0.RELEASE.jar
12.2.3. Working with Neo4jTemplate 12.2.4. Creating automatic Neo4j repositories 12.3. Working with key-value data in Redis 12.3.1. Connecting to Redis 12.3.2. Working with RedisTemplate 12.3.3. ...