![]() |
#2
Alex11112012-03-28 13:50
|

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jTemplates</title>
</head>
<body>
<div id="result"></div>
<div id="foreachResult"></div>
</body>
<script src="http://ajax.
<script src="http://jtemplates.
<BR><script type="text/template" id="foreach">
<table>
<thead>
<tr>
<td>Index</td>
<td>ID</td>
<td>Name</td>
<td>Age</td>
<td>Mail</td>
</tr>
</thread>
<tbody>
{#foreach $T.table as record begin=1}
<tr>
<td>{$T.record$index}</td>
<td>{$T.record.id}</td>
<td>{$T.record.name}</td>
<td>{$T.record.age}</td>
<td>{$T.record.mail}</td>
</tr>
{#/for}
</tbody>
</table>
</script>
<script>
$(function($) {
var data = {
name: 'User list',
list_id: 6,
table: [
{ id: 1, name: 'Alex', age: 21, mail: 'Alex@' },
{ id: 2, name: 'Amelie', age: 24, mail: 'amelie@' },
{ id: 3, name: 'Polly', age: 18, mail: 'polly@' },
{ id: 4, name: 'Alice', age: 26, mail: 'alice@' },
{ id: 5, name: 'Martha', age: 25, mail: 'martha@' }
]
};
var mydata = { name: "Alex", age: "21" };
$("#result").setTemplate("My name is {$T.name}");
$("#result").processTemplate(mydata);
$('#foreachResult').setTemplate($('#foreach').html()).processTemplate(data);
$('#foreachResult').delegate('td', 'click', function() {
alert($(this).text());
});
});
</script>
</html>
{#foreach $T.table as record begin=1}中如果把begin去掉的话就不会显示数据了 怎么回事??? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jTemplates</title>
</head>
<body>
<div id="result"></div>
<div id="foreachResult"></div>
</body>
<script src="http://ajax.
<script src="http://jtemplates.
<BR><script type="text/template" id="foreach">
<table>
<thead>
<tr>
<td>Index</td>
<td>ID</td>
<td>Name</td>
<td>Age</td>
<td>Mail</td>
</tr>
</thread>
<tbody>
{#foreach $T.table as record begin=1}
<tr>
<td>{$T.record$index}</td>
<td>{$T.record.id}</td>
<td>{$T.record.name}</td>
<td>{$T.record.age}</td>
<td>{$T.record.mail}</td>
</tr>
{#/for}
</tbody>
</table>
</script>
<script>
$(function($) {
var data = {
name: 'User list',
list_id: 6,
table: [
{ id: 1, name: 'Alex', age: 21, mail: 'Alex@' },
{ id: 2, name: 'Amelie', age: 24, mail: 'amelie@' },
{ id: 3, name: 'Polly', age: 18, mail: 'polly@' },
{ id: 4, name: 'Alice', age: 26, mail: 'alice@' },
{ id: 5, name: 'Martha', age: 25, mail: 'martha@' }
]
};
var mydata = { name: "Alex", age: "21" };
$("#result").setTemplate("My name is {$T.name}");
$("#result").processTemplate(mydata);
$('#foreachResult').setTemplate($('#foreach').html()).processTemplate(data);
$('#foreachResult').delegate('td', 'click', function() {
alert($(this).text());
});
});
</script>
</html>